A bank has a base Account class. SavingsAccount inherits and adds yearly compound interest.
Account:
id (String), balance (double)void deposit(double amt) adds to balance.double getBalance().SavingsAccount extends Account:
double rate — yearly interest rate (e.g. 0.06).double balanceAfterYears(int years): returns balance * (1+rate)^years (compound interest).<id> <balance> <rate>.DEPOSIT <id> <amt> — call deposit. After the command print <id> <getBalance> (2 decimal places).FORECAST <id> <years> — print <id> <balanceAfterYears> (2 decimal places). Balance is unchanged.<id> <balance> <rate>Each command prints 1 line per the rules above (2 decimal places).
Ví dụ:
Đầu vào:
1
A1 1000000 0.1
2
DEPOSIT A1 500000
FORECAST A1 2
Đầu ra:
A1 1500000.00
A1 1815000.00
Giải thích:
Đầu vào:
1
B 1000 0
1
FORECAST B 10
Đầu ra:
B 1000.00
Giải thích:
Đầu vào:
2
C1 100 0.05
C2 200 0.1
2
FORECAST C1 1
FORECAST C2 1
Đầu ra:
C1 105.00
C2 220.00
Đầu vào:
1
X 0 0.1
2
DEPOSIT X 1000
FORECAST X 5
Đầu ra:
X 1000.00
X 1610.51
Đang tải editor...