Loading...
Loading...
A savings account must never fall below a minimum balance, and amounts of zero or less are refused. Process a list of commands for one account.
Write a class BankAccount with fields holder, balance and minBalance, a method void deposit(long amount) and a method boolean withdraw(long amount) that returns false and changes nothing when the rule would break.
deposit x, withdraw x or balance.OK newBalance after a successful deposit or withdrawal, INVALID AMOUNT when x ≤ 0, INSUFFICIENT FUNDS when a withdrawal would go below the minimum, and holder BALANCE b for balance.Example
Input
Asha 1000 500 5 deposit 500 withdraw 800 withdraw 300 balance deposit -50
Output
OK 1500 OK 700 INSUFFICIENT FUNDS Asha BALANCE 700 INVALID AMOUNT
After 1500 - 800 = 700, taking 300 more would leave 400, below 500.
Try the problem first. Open one hint at a time.
A withdrawal is allowed only when balance - amount >= minBalance.
Check the amount first (x <= 0), then call the method.
balance has no number after it, so read x only for the other two commands.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor