There was an error while loading. Please reload this page.
1 parent 7d433cc commit 5ce630aCopy full SHA for 5ce630a
Part3/Retirement.java
@@ -0,0 +1,29 @@
1
+import java.util.*;
2
+
3
+public class Retirement {
4
+ public static void main(String[] args) {
5
+ Scanner in = new Scanner(System.in);
6
7
+ System.out.print("How much money do you need to retire? ");
8
+ double goal = in.nextDouble();
9
10
+ System.out.print("How much money will you contribute every year? ");
11
+ double payment = in.nextDouble();
12
13
+ System.out.print("Interest rate in %: ");
14
+ double interestRate = in.nextDouble();
15
16
+ double balance = 0;
17
+ int years = 0;
18
19
+ while (balance < goal) {
20
+ balance += payment;
21
+ double intrest = balance * interestRate / 100;
22
+ balance += intrest;
23
+ years++;
24
+ }
25
26
+ System.out.println("You can retire in " + years + " years.");
27
28
+}
29
0 commit comments