Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

TASK 1 Create a new class called CheckingAccount that extends BankAccount. It sh

ID: 3658736 • Letter: T

Question

TASK 1


Create a new class called CheckingAccount that extends BankAccount.

It should contain a static constant FEE that represents the cost of clearing onecheck. Set it equal to 15 cents.

Write a constructor that takes a name and an initial amount as parameters. Itshould call the constructor for the superclass. It should initializeaccountNumber to be the current value in accountNumber concatenatedwith -10 (All checking accounts at this bank are identified by the extension -10). There can be only one checking account for each account number.Remember since accountNumber is a privatemember in BankAccount, itmust be changed through a mutator method.

Write a new instance method, withdraw, that overrides the withdraw method inthe superclass. This method should take the amount to withdraw, add to it thefee for check clearing, and call the withdraw method from the superclass.Remember that to override the method, it must have the same method heading.Notice that the withdraw method from the superclass returns true or falsedepending if it was able to complete the withdrawal or not. The method thatoverrides it must also return the same true or false that was returned from thecall to the withdraw method from the superclass.



Explanation / Answer

// Create a new class called CheckingAccount that extends BankAccount.
public class CheckingAccount extends BankAccount
{
    // It should contain a static constant FEE that represents the cost of clearing onecheck. Set it equal to 15 cents.
    public static final double FEE = 0.15;
   
    // Write a constructor that takes a name and an initial amount as parameters.
    public CheckingAccount(String name, double initialAmount)
    {
        // It should call the constructor for the superclass.
        super(name, initialAmount);
        // It should initialize accountNumber to be the current value in accountNumber concatenated with -10 (All checking accounts at this bank are identified by the extension -10). There can be only one checking account for each account number.Remember since accountNumber is a private member in BankAccount, it must be changed through a mutator method.
        setAccountNumber(getAccountNumber()+"-10");
    }
    // Write a new instance method, withdraw, that overrides the withdraw method in the superclass. This method should take the amount to withdraw, add to it the fee for check clearing, and call the withdraw method from the superclass. Remember that to override the method, it must have the same method heading.Notice that the withdraw method from the superclass returns true or false depending if it was able to complete the withdrawal or not. The method thatoverrides it must also return the same true or false that was returned from thecall to the withdraw method from the superclass.
    public boolean withdraw(double amount)
    {
        return super.withdraw(amount+FEE);
    }
}