01: /**
02:    A checking account that charges transaction fees.
03: */
04: public class CheckingAccount extends BankAccount
05: {  
06:    /**
07:       Constructs a checking account with a given balance.
08:       @param initialBalance the initial balance
09:    */
10:    public CheckingAccount(double initialBalance)
11:    {  
12:       // Construct superclass
13:       super(initialBalance);
14:       
15:       // Initialize transaction count
16:       transactionCount = 0; 
17:    }
18: 
19:    public void deposit(double amount) 
20:    {  
21:       transactionCount++;
22:       // Now add amount to balance 
23:       super.deposit(amount); 
24:    }
25:    
26:    public void withdraw(double amount) 
27:    {  
28:       transactionCount++;
29:       // Now subtract amount from balance 
30:       super.withdraw(amount); 
31:    }
32: 
33:    /**
34:       Deducts the accumulated fees and resets the
35:       transaction count.
36:    */
37:    public void deductFees()
38:    {  
39:       if (transactionCount > FREE_TRANSACTIONS)
40:       {  
41:          double fees = TRANSACTION_FEE *
42:                (transactionCount - FREE_TRANSACTIONS);
43:          super.withdraw(fees);
44:       }
45:       transactionCount = 0;
46:    }
47: 
48:    private int transactionCount;
49: 
50:    private static final int FREE_TRANSACTIONS = 3;
51:    private static final double TRANSACTION_FEE = 2.0;
52: }