public class CheckingAccount extends BankAccount { private double monthlyFee = 5.95; private AccountFee fee; public CheckingAccount(double deposit) { super(); if( deposit >= 1000.0 ) { fee = new NoFee(); } else { fee = new MonthlyFee(); } // end if makeDeposit(deposit); } // end CheckingAccount public void calculateFee() { subtractFromBalance(fee.accountFee()); addToStatement(fee + ""); } // end calculateFee public void setMonthlyFee(double amount) { monthlyFee = amount; } // end setMonthlyFee public double getMonthlyFee() { return monthlyFee; } // end getMonthlyFee public boolean makeWithdrawal(double amount) { boolean OK = super.makeWithdrawal(amount); if( !OK ) return false; double balance = getBalance(); if( balance < 1000.0 ) { fee = new MonthlyFee(); } // end if return true; } // end makeWithdrawal private interface AccountFee { public double accountFee(); } private class NoFee implements AccountFee { public double accountFee(){ return 0.0; } // end accountFee public String toString() { return ""; } // end toString } // end NoFee private class MonthlyFee implements AccountFee { public double accountFee(){ return monthlyFee; } // end accountFee public String toString() { return "Fee: " + accountFee() + "\nNew balance: " + getBalance() + "\n"; }// end toString() } // end MonthlyFee } // end CheckingAccount