
/*
 * This is a bank account that keeps track of a number
 * of transactions; if the transactions goes over a specified
 * amount, it withdraws a transaction fee from the account
 */

//
// CheckingAccount is the subclass, 
// BankAccount is the superclass.
// If you don't explicitly extend some other class, Java
// will automatically make classes you define extend the 
// java.lang.Object class
//
public class CheckingAccount extends BankAccount {
   public static final double TRANS_FEE = 10.00;
   public static final int FREE_TRANS = 5;
   
   // The CheckingAccount class 'inherits' the balance field of
   // BankAccount, but because that field is private in the 
   // superclass, you cannot directly access it in the subclass
   
   // number of transactions
   private int transactions;

   // constructor
   public CheckingAccount() {
      //super();  // even if you don't put this superclass constructor call
                  // here, Java will insert such a call to the default
                  // (i.e. no-parameter) superclass constructor
      transactions = 0;
   }
   
   public CheckingAccount( double initialBalance ) {
      super( initialBalance );  // explicitly calling a superclass constructor
      transactions = 0;
   }
   
   // These methods *override* (i.e. redefine) the methods in the superclass
   // In this case, we add code to these methods to have them keep
   // track of the number of transactions that have taken place
   public void deposit( double amt ) {
      transactions++;
      super.deposit( amt );
   }
   
   public void withdraw( double amt ) {
      transactions++;
      super.withdraw( amt );
   }
   
}
