• java 笔记一些


    面象对的umv 视图示例:

    用户  银行  帐户  怎么关联

    帐户代码:

    文件命名 Account

    package com.atuigu.exer4;
    
    import org.omg.CORBA.PUBLIC_MEMBER;
    
    public class Account {
        private double balance;
        
        public Account(double init_balance) {
            this.balance = init_balance;
           
        }
        
        public double getBalance() {
            return balance;
        }
    
        public void deposit(double amt) {
            if(amt>0) {
                balance +=amt;
                System.out.println("存钱成功");
            }        
        }
        
        public void withdraw(double amt) {
            if(balance>=amt) {
                balance-=amt;
                System.out.println("余额不足");
            }
        }//
        
        
    }//主函数结束
    View Code

    银行代码:文件命名:Customer

    package com.atuigu.exer4;
    
    public class Customer {
        private String firstName;
        private String lastName;
        private Account account;
        public Customer(String f, String l) {
            this.firstName = f;
            this.lastName = l;
            
        }
        public String getFirstName() {
            return firstName;
        }
        public void setFirstName(String firstName) {
            this.firstName = firstName;
        }
        public String getLastName() {
            return lastName;
        }
        public void setLastName(String lastName) {
            this.lastName = lastName;
        }
        public Account getAccount() {
            return account;
        }
        public void setAccount(Account account) {
            this.account = account;
        }
        
    
    }
    View Code

    用户代码:文件命名:Bank

    package com.atuigu.exer4;
    
    public class Bank {
        private Customer[] customers;
        //定义一个可以装很多用户的数组类;
        private int  numberofCustomer;
        
        public Bank() {
            customers = new Customer[10];
            
        }
        
        public void addCustomer(String f,String l) {
            Customer cust = new Customer(f,l);
            customers[numberofCustomer] = cust;
            numberofCustomer++;
            
        }
        
        public int getNumofCustomers(){
            return numberofCustomer;
            
        }
        
        public Customer getCustomer(int index) {
            if(index>=0 && index < numberofCustomer){
            return customers[index];
            }
            return null;
            
            
        }
        
        
        
            
        }
    View Code

    主函数代码示例:文件命名:BankTest

    package com.atuigu.exer4;
    
    public class BankTest {
        public static void main(String[] args) {
            Bank bank = new Bank();
            bank.addCustomer("jane","Smith");
            bank.addCustomer("ok", "err");
            
            Account a = new Account(2000);
            
            bank.getCustomer(0).setAccount(a);
            
            bank.getCustomer(0).getAccount().withdraw(500);
            double balance = bank.getCustomer(0).getAccount().getBalance();
            System.out.print(""+bank.getCustomer(0).getFirstName());
            System.out.println("奶奶的银业有我少个"+ bank.getNumofCustomers());
            
            
            
        }
    
    }
    View Code
  • 相关阅读:
    Post请求data参数构造及巧用js脚本显示爬虫进度
    Javascript动态生成的页面信息爬取和openpyxl包FAQ小记
    Selenium实战脚本集—新浪微博发送QQ每日焦点
    linux下如何使用Mysql
    selenium 点击页面链接测试
    功能测试工具Selenium IDE
    JAVA + SELENIUM--环境搭建
    将Sublime Text 2搭建成一个好用的IDE
    Appium(JAVA)Windows 7系统搭建及示例运行
    python 进行web测试
  • 原文地址:https://www.cnblogs.com/fgxwan/p/11146640.html
Copyright © 2020-2023  润新知