Loading...
Loading...
A small bank pays the same yearly interest rate on every savings account. When the rate changes, it changes for all accounts at once. Account numbers start at 5001.
Write a class Account with a static int ratePercent (starts at 4), a static int nextNumber, final fields number and holder, a balance field and a method long addInterest() that adds balance × ratePercent / 100 (rounded down) and returns it.
open name amount, rate r, year or show number.open: OPENED number name. rate: RATE r FOR ALL. year: INTEREST PAID total (the sum over all accounts). show: number name balance or NO ACCOUNT number.year commandsExample
Input
6 open Asha 10000 open Ravi 5000 year rate 10 year show 5001
Output
OPENED 5001 Asha OPENED 5002 Ravi INTEREST PAID 600 RATE 10 FOR ALL INTEREST PAID 1560 5001 Asha 11440
Year one pays 4% (600 in all); after the change both accounts earn 10%.
Try the problem first. Open one hint at a time.
ratePercent is one value for the whole class, so the rate command changes it once with Account.ratePercent = r.
Store the accounts in an array of size q with a count, and find account n at index n - 5001.
For year, call addInterest() on every account and add up the results.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor