zoukankan      html  css  js  c++  java
  • bank

    package bankinghomework;
    public class Customer {
        //属性
        private String firstName;
        private String lastName;
        private Account account;
        //构造器
        Customer(){};
        Customer(String f,String l){
            this.firstName=f;
            this.lastName=l;
        }
        //存取器
        public String getFirstName() {                    //firstName
            return firstName;
        }
        public void setFirstName(String firstName) {
            this.firstName = firstName;
        }
        public String getLastName() {                    //lastName
            return lastName;
        }
        public void setLastName(String lastName) {
            this.lastName = lastName;
        }
        //存取器
        public Account getAccount() {
            return account;
        }
        public void setAccount(Account acct) {
            this.account=acct;
        }
        @Override
        public String toString() {
            return firstName + "," + lastName;
        }
    }
    
    
    package bankinghomework;
    import java.util.ArrayList;
    import java.util.List;
    
    public class Bank{
        private List<Customer> customers;             //customers集合
        private int numberOfCustomers;                //记录客户数量
        public Bank(){                                //构造方法,初始化customers
            customers=new ArrayList<Customer>();
        }
        public void addCustomer(String f,String l){        //方法:往customers里面添加Customer对象
            Customer p=new Customer(f,l);
            customers.add(p);
        }
        public int getNumOfCustomers(){                   //获取客户数量,即获取customers的长度
            numberOfCustomers=customers.size();
            return numberOfCustomers;
        }
        public Customer getCustomer(int index){            //根据索引取值return customers.get(index); 
      }
     }
    public class TestBanking {
        public static void main(String[] args) {
            Bank cus=new Bank(){};
            cus.addCustomer("Simms", "Jane");
            cus.addCustomer("Bryant", "Owen");
            cus.addCustomer("Soley","Tim");
            cus.addCustomer("Soley","Maria");
            for(int i=0;i<cus.getNumOfCustomers();i++){
                System.out.println("Customer "+(i+1)+" is"+" "+cus.getCustomer(i));
            }  
    }
    

      

  • 相关阅读:
    记录一次线上优化流程
    php ignite 使用问题记录
    invalid contrller specified 错误分析及解决
    koa 2 的 async 和 await 语法
    koa 2 的安装
    vue 自定义组件 v-model双向绑定、 父子组件同步通信的多种写法
    VS2019专业版和企业版激活密钥
    RE:ゼロから始める PKU 生活 episode 2
    CSP-S 2020 游记
    ioi2021集训队作业
  • 原文地址:https://www.cnblogs.com/zhangnaitao/p/5907884.html
Copyright © 2011-2022 走看看