Loading...
Loading...
A plain account refuses withdrawals larger than its balance. A savings account is an account with two extra rules: it must keep a minimum balance, and interest adds rate% of the balance (rounded down).
Write Account (private holder and balance, deposit, boolean withdraw) and SavingsAccount extends Account whose withdraw checks the minimum and then calls super.withdraw(amount).
deposit x, withdraw x, interest or balance.BALANCE b after a deposit or a successful withdrawal, BELOW MINIMUM for a refused one, INTEREST i BALANCE b for interest, holder b for balance.Example
Input
Asha 5000 1000 4 5 withdraw 3500 withdraw 600 interest deposit 900 balance
Output
BALANCE 1500 BELOW MINIMUM INTEREST 60 BALANCE 1560 BALANCE 2460 Asha 2460
After 1500, taking 600 would leave 900, below the minimum of 1000.
Try the problem first. Open one hint at a time.
Only the extra rule goes in the child: if (getBalance() - amount < minBalance) return false;, then return super.withdraw(amount);.
Interest is getBalance() * rate / 100; add it with the inherited deposit.
balance reads no number after it.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor