A certain bank offers 6.5% interest on savings accounts, compounded annually. Create a table that shows how much money a person will accumulate over a period of 25 years, assuming that the person makes an initial investment of $1000 and deposits $100 each year after the first. Your table should indicate for each year the current balance, the interest, the new deposit, and the new balance.
Program:
public class Ch03PP02
{
public static void main(String[] args)
{
double P = 1000;
double r = 0.065; // 6.5%
double t = 1; // yearly term
int n = 25;
double deposit = 100;
double A;
double interest;
double newBalance;
System.out.println("YEAR\tCURRENT_BALANCE\t\tINTEREST\tNEW_DEPOSIT\tNEW_BALANCE");
for(int year = 1; year <= n; year++)
{
A = P * (1 + r * t);
interest = A - P;
newBalance = A + deposit;
System.out.println(year + "\t" + round2(P) + "\t\t\t" + round2(interest)
+ "\t\t" + round2(deposit) + "\t\t" + round2(newBalance));
P = newBalance;
}
}
public static double round2(double value)
{
return Math.round(value * 100.0) / 100.0;
}
}
Output:
YEAR CURRENT_BALANCE INTEREST NEW_DEPOSIT NEW_BALANCE
1 1000.0 65.0 100.0 1165.0
2 1165.0 75.72 100.0 1340.73
3 1340.73 87.15 100.0 1527.87
4 1527.87 99.31 100.0 1727.18
5 1727.18 112.27 100.0 1939.45
6 1939.45 126.06 100.0 2165.52
7 2165.52 140.76 100.0 2406.27
8 2406.27 156.41 100.0 2662.68
9 2662.68 173.07 100.0 2935.76
10 2935.76 190.82 100.0 3226.58
11 3226.58 209.73 100.0 3536.31
12 3536.31 229.86 100.0 3866.17
13 3866.17 251.3 100.0 4217.47
14 4217.47 274.14 100.0 4591.6
15 4591.6 298.45 100.0 4990.06
16 4990.06 324.35 100.0 5414.41
17 5414.41 351.94 100.0 5866.35
18 5866.35 381.31 100.0 6347.66
19 6347.66 412.6 100.0 6860.26
20 6860.26 445.92 100.0 7406.18
21 7406.18 481.4 100.0 7987.58
22 7987.58 519.19 100.0 8606.77
23 8606.77 559.44 100.0 9266.21
24 9266.21 602.3 100.0 9968.51
25 9968.51 647.95 100.0 10716.47