Skip to content

Commit 1ea55ac

Browse files
finished exercise 31
1 parent e32c84a commit 1ea55ac

File tree

1 file changed

+37
-4
lines changed

1 file changed

+37
-4
lines changed

src/com/github/jonathanbirkey/chapter05/Exercise31.java

+37-4
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,47 @@
22
* @author : Jonathan Birkey
33
* @mailto : [email protected]
44
* @created : 28Feb2024
5-
* <p>(Display leap years) Write a program that displays all the leap years, 10 per line, from
6-
* 101 to 2100, separated by exactly one space. Also display the number of leap years in this
7-
* period.
5+
* <p>(Financial application: compute CD value) Suppose you put $10,000 into a CD with an annual
6+
* percentage yield of 5.75%. After one month, the CD is worth
7+
* <p>10000 + 10000 * 5.75 / 1200 = 10047.92
8+
* <p>After two months, the CD is worth
9+
* <p>10047.91 + 10047.91 * 5.75 / 1200 = 10096.06
10+
* <p>After three months, the CD is worth
11+
* <p>10096.06 + 10096.06 * 5.75 / 1200 = 10144.44
12+
* <p>and so on.
13+
* <p>Write a program that prompts the user to enter an amount (e.g., 10000), the annual
14+
* percentage yield (e.g., 5.75), and the number of months (e.g., 18) and displays a table as
15+
* presented in the sample run.
16+
* <p>Enter the initial deposit amount: 10000
17+
* <p>Enter annual percentage yield: 5.75
18+
* <p>Enter maturity period (number of months): 18
19+
* <p>Month CD Value
20+
* <p>1 100047.92
21+
* <p>2 10096.06
22+
* <p>...
23+
* <p>17 10846.57
24+
* <p>18 10898.54
825
*/
926
package com.github.jonathanbirkey.chapter05;
1027

28+
import java.util.Scanner;
29+
1130
public class Exercise31 {
1231
public static void main(String[] args) {
13-
// TODO: solve
32+
Scanner input = new Scanner(System.in);
33+
System.out.print("Enter the initial deposit amount: ");
34+
double amount = input.nextDouble();
35+
System.out.print("Enter annual percentage yield: ");
36+
double APY = input.nextDouble();
37+
System.out.print("Enter maturity period (number of months): ");
38+
int months = input.nextInt();
39+
input.close();
40+
41+
System.out.printf("Month\tCD Value\n");
42+
43+
for (int i = 1; i <= months; i++) {
44+
amount = amount + (amount * (APY / 1200));
45+
System.out.printf("%-7d %.2f\n", i, amount);
46+
}
1447
}
1548
}

0 commit comments

Comments
 (0)