UNB/ CS/ David Bremner/ teaching/ old/ cs1083/ java/ CheckingAccount.java
import java.math.BigDecimal;
public class CheckingAccount extends DecimalAccount {

    private int transactionCount;

    private static final int FREE_TRANSACTIONS = 3;
    private static final BigDecimal TRANSACTION_FEE = new BigDecimal(2);

    public CheckingAccount(long dollars, int cents) {
        // construct superclass
        super(dollars, cents);

        // initialize transaction count
        transactionCount = 0;
    }

    final public void deposit(BigDecimal amount)
    {  transactionCount++;
        // now add amount to balance
        super.deposit(amount);
    }

    final public void withdraw(BigDecimal amount)
    {  transactionCount++;
        // now subtract amount from balance
        super.withdraw(amount);
    }

    public void deductFees()
    {  if (transactionCount > FREE_TRANSACTIONS)
            {  BigDecimal fees = TRANSACTION_FEE.multiply(new BigDecimal(transactionCount - FREE_TRANSACTIONS));
                super.withdraw(fees);
            }
        transactionCount = 0;
    }

}