01: /**
02: A checking account that charges transaction fees.
03: */
04: publicclassCheckingAccountextendsBankAccount
05: {
06: /**
07: Constructs a checking account with a given balance.
08: @param initialBalance the initial balance
09: */
10: publicCheckingAccount(doubleinitialBalance)
11: {
12: // Construct superclass
13: super(initialBalance);
14:
15: // Initialize transaction count
16: transactionCount=0;
17: }
18:
19: publicvoiddeposit(doubleamount)
20: {
21: transactionCount++;
22: // Now add amount to balance
23: super.deposit(amount);
24: }
25:
26: publicvoidwithdraw(doubleamount)
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: publicvoiddeductFees()
38: {
39: if(transactionCount>FREE_TRANSACTIONS)
40: {
41: doublefees=TRANSACTION_FEE*
42: (transactionCount-FREE_TRANSACTIONS);
43: super.withdraw(fees);
44: }
45: transactionCount=0;
46: }
47:
48: privateinttransactionCount;
49:
50: privatestaticfinalintFREE_TRANSACTIONS=3;
51: privatestaticfinaldoubleTRANSACTION_FEE=2.0;
52: }
0 Comments