/** * @author KR * CheckingAccount.java * Project Assignment #8 */ public class CheckingAccount extends Account { //Declare transaction counter and initialize to 0 private int transactions=0; //Declare constant for number of free transactions private static final int FREE_TRANSACTIONS = 5; //Declare constant for transaction fee applied if num of transactions > //than FREE_TRANSACTIONS private static final double TRANSACTION_FEE = 1.50; /******************* Constructor Methods *********************/ //Subclass constructor. Call superclass constructor as first statement. public CheckingAccount( double startBalance ) { //Call superclass constructor and pass provided startBalance value. super ( startBalance ); } /******************* Accessor Methods *********************/ //No additional accessor methods needed. Use methods inherited from //superclass. /******************* Mutator Methods *********************/ //Different methods are needed to override deposit and withdraw methods //of Account class. These methods increment a transaction count required //by CheckingAccount. //Mutator method to increase account balance, simulating a cash deposit. //This overrides the superclass Account's deposit method, and will be the //deposit method used by CheckingAccount objects. It increments the //transaction counter, and then calls the superclass deposit method //to execute the statements in it. public void deposit ( double anotherAmount ) { transactions++; super.deposit ( anotherAmount ); } //Mutator method to decrease account balance, simulating a cash withdrawal //or a check deducted. This overrides the superclass Account's withdraw //method, and will be the withdrawal method used by CheckingAccount objects. //It increments the transaction counter, and then calls the superclass withdraw //method to execute the statements in it. public void withdraw ( double moneyAmount ) { transactions++; super.withdraw ( moneyAmount ); } //Mutator method to deduct transaction fees, if any, and reset transaction //counter to 0. public void deductFees () { //Check if number of transactions > number of free transactions. if ( transactions > FREE_TRANSACTIONS ) { //If true, multiply fee by number of transactions exceeding free ones double fees = TRANSACTION_FEE * ( transactions - FREE_TRANSACTIONS ); //If true, subtract fees from account. Use the superclass Account's //withdraw method rather than CheckingAccount's version of withdraw so //that we do not increment the number of transactions by deducting fees. super.withdraw ( fees ); } //After fees have been deducted, reset transaction counter to 0 transactions = 0; } /******************* Facilitator ("Helper" Methods *********************/ //No additional facilitator methods needed. Use methods inherited from //superclass Account. /******************* toString Methods *********************/ //Use the toString method inherited from superclass Account. }