//An instance of this class represents a simple checking account // It permits a limited number of withdrawals in a billing cycle // and charges an (excess) fee for withdrawals over the limit // package BankAccounts; public class CheckingAccount extends BankAccount { //Class constants public static int MAX_WITHDRAWALS = 3; public static double WITHDRAWALS_FEE = 1.00; //Instance (State) Variable (inherited: accountNumber & currentBalance) private int withdrawalsCount; //# withdrawals in billing cycle so far //Constructor // @param initialBalance: initial current balance of thisCheckingAccount public CheckingAccount(double initialBalance) { super(initialBalance); this.withdrawalsCount = 0; } //Constructor // initial current balance of thisCheckingAccount defaults to $0.0 public CheckingAccount() { this(0.0); } //Accessor public int getWithdrawalsCount() { return this.withdrawalsCount; } //Override public String toString() { return super.toString() + " # Withdrawals: " + this.withdrawalsCount; } //Override public boolean equals(Object other) { if (!super.equals(other)) return false; return this.withdrawalsCount == ( (CheckingAccount)other ).withdrawalsCount; } //Will override clone() later //Override public void withdraw(double amount) { super.withdraw(amount); this.withdrawalsCount++; } //Mutator // Deduct fees for excess withdrawals from this CheckingAccount public void debitFees() { double fees = this.withdrawalsCount <= MAX_WITHDRAWALS ? 0.00 : (this.withdrawalsCount - MAX_WITHDRAWALS) * WITHDRAWALS_FEE ; this.debit(fees); } //Mutator public void endOfCycleProcessing() { this.debitFees(); this.withdrawalsCount = 0; } }