//银行类
class Bank{
private Customer[] customers; //Customers对象 客户数组
private int numberOfCustomers; //整数,跟踪下一个customers数组索引
//初始化数组 共有的空参构造器
public Bamk(){
customers = new Customer[10];
}
//添加客户信息的方法
public void addCustomer(String firstName, String lastName){
//创建客户对象
Customer customer = new Customer(fistName,lastName)
Customers[numberOfCustomers] =customer;
numberOfCustomers++;
}
//返回对应下标客户
public Customer getCustomers(int index) {
return customers[index];
}
public int getNumberofCustomers() {
return numberofCustomers;
}
}
//测试类
public class TestBanking {
public static void main(String[] args) {
Bank bank = new Bank();
// Add Customer Jane, Simms
bank.AddCustomer("Jane"," Simms");
//code
//Add Customer Owen, Bryant
bank.AddCustomer("Owen"," Bryant");
//code
// Add Customer Tim, Soley
bank.AddCustomer("Tim"," Soley");
//code
// Add Customer Maria, Soley
ank.AddCustomer("Maria"," Soley");
//code
for ( int i = 0; i < bank.getNumOfCustomers(); i++ ) {
Customer customer = bank.getCustomer(i);
System.out.println("Customer [" + (i+1) + "] is "
+ customer.getLastName()
+ ", " + customer.getFirstName());
}
}
}