• 【Java 基础项目


    UML设计:

    文件组织:

    (注: 在bank4中,直接调用bank3的内容, 不再重复编写代码即可!)

    代码编写Bank.java:

    package Banking_4;
    
    import Banking_3.*;
    
    public class Bank {
        private Customer[] customers ;   //用于存放客户
        private int numberofCustomers; //用于记录Customer的个数
    
        public Bank(){
            numberofCustomers=0;
            customers = new Customer[100];  ///这里记得要初始化!不然要发生java.lang.NullPointerException
        }
        public void addCustomer(String f,String l){
            int i=this.numberofCustomers++;
            customers[i]=new Customer(f,l);//新建一个构造对象
        }
    
        public int getNumOfCustomers() {
            return numberofCustomers;
        }
        public Customer getCustomer(int index) {
            return customers[index];
        }
    }

    2/TestBanking4.java

    package Banking_4;
    
    import Banking_3.*;
    
    public class Bank {
        private Customer[] customers ;   //用于存放客户
        private int numberofCustomers; //用于记录Customer的个数
    
        public Bank(){
            numberofCustomers=0;
            customers = new Customer[100];  ///这里记得要初始化!不然要发生java.lang.NullPointerException
        }
        public void addCustomer(String f,String l){
            int i=this.numberofCustomers++;
            customers[i]=new Customer(f,l);//新建一个构造对象
        }
    
        public int getNumOfCustomers() {
            return numberofCustomers;
        }
        public Customer getCustomer(int index) {
            return customers[index];
        }
    }

    运行结果:

    Customer [1] is Simms, Jane
    Customer [2] is Bryant, Owen
    Customer [3] is Soley, Tim
    Customer [4] is Soley, Maria
  • 相关阅读:
    关于明确我校教学作息时间的通知
    放假时间
    五一上课表
    课表
    mysql 数据库备份与还原
    默默的追随
    2004上半年
    IE慢吗?
    创建的permission java.security.AllPermission;文件,用于加密
    数据库驱动
  • 原文地址:https://www.cnblogs.com/zhazhaacmer/p/9767949.html
Copyright © 2020-2023  润新知