



在题目给出的代码之后加入我的代码,一直没有结果。(题目说给出的代码可能有错,但是我找不到)
class Bank{
private Customer[] customers;
private int numOfCustomers;
public Bank(){
customers = new Customer[5];
}
public Customer getCustomer(int i) {
return customers[i];
}
public void addCustomer(String f, String l){
Customer customer = new Customer(f, l);
customers[numOfCustomers++] = customer;
}
public int getNumOfCustomers(){
return numOfCustomers;
}
}
class Account{
protected double balance;
public Account(double balance) {
this.balance = balance;
}
public double getBalance() {
return balance;
}
public boolean deposit(double amt){
balance += amt;
return true;
}
public boolean withdraw(double amt){
if (amt<=balance){
balance -= amt;
return true;
}else{
return false;
}
}
}
class SavingsAccount extends Account{
public double interestRate;
public SavingsAccount(double balance, double interestRate) {
super(balance);
this.interestRate = interestRate;
}
}
class CheckingAccount extends Account{
public double overdraftProtection;
public CheckingAccount(double balance) {
super(balance);
}
public CheckingAccount(double balance, double overdraftProtection) {
super(balance);
this.overdraftProtection = overdraftProtection;
}
public boolean withdraw(double amt){
if (amt<=balance){
balance -= amt;
return true;
}else if(amt - balance <= overdraftProtection){
balance = 0;
overdraftProtection -= amt-balance;
return true;
}else{
return false;
}
}
}
class Customer{
private String firstname;
private String lastname;
private Account[] account;
private int numOfAccounts;
public Customer(String firstname, String lastname) {
this.firstname = firstname;
this.lastname = lastname;
account = new Account[5];
}
public String getFirstName() {
return firstname;
}
public String getLastName() {
return lastname;
}
public void addAccount(Account ac){
account[numOfAccounts] = ac;
numOfAccounts++;
}
public int getNumOfAccounts(){
return numOfAccounts;
}
public Account getAccount(int index){
return account[index];
}
}
结果如下图:

求解决