Day08_11练习04

这里写图片描述

//银行类 

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()); 
         }
      }
   }  

这里写图片描述

阅读更多
文章标签: d
个人分类: l
上一篇Day08_11练习03
下一篇java数组初始化
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭