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

Given an existing class, BankAccount, containing: a constructor accepting a Stri

ID: 3652338 • Letter: G

Question

Given an existing class, BankAccount, containing:
a constructor accepting a String corresponding to the name of the account holder.
a method, getBalance, that returns a double corresponding to the account balance.
a method withdraw that accepts a double, and deducts the amount from the account balance.
Write a class definition for a subclass, CheckingAccount, that contains:
a boolean instance variable, overdraft. (Having overdraft for a checking account allows one to write checks larger than the current balance).

Explanation / Answer

class CheckingAccount extends BankAccount { CheckingAccount(String name, boolean overdraft) { super(name); this.overdraft = overdraft; } boolean hasOverdraft() {return overdraft;} boolean clearCheck(double amount) { if (getBalance() >= amount || overdraft) { withdraw(amount); return true; } return false; } boolean overdraft; }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote