Loading...
Loading...
A basic account may not go below 0. A savings account must keep at least Rs. 1000. A current account may go down to Rs. -5000 (an overdraft). Write Account with boolean canWithdraw(long amount) and boolean withdraw(long amount); children override only canWithdraw, and withdraw in the parent uses it.
BASIC, SAVINGS or CURRENT), a one-word name and the opening balance. The next line has q, then q lines i amount: withdraw from account i (1-based).<name> OK <balance> or <name> DECLINED <balance>.Example
Input
3 BASIC Asha 500 SAVINGS Ravi 3000 CURRENT Meena 1000 4 1 500 2 2500 3 6000 3 1
Output
Asha OK 0 Ravi DECLINED 3000 Meena OK -5000 Meena DECLINED -5000
Ravi would drop to 500, below 1000. Meena reaches exactly -5000, then cannot go lower.
Try the problem first. Open one hint at a time.
In the parent: if (!canWithdraw(amount)) return false; balance -= amount; return true;.
Savings: balance - amount >= 1000. Current: balance - amount >= -5000.
Keep balance private in Account and give the children a getBalance() to read it.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor