forked from mthli/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRetirement2.java
More file actions
33 lines (23 loc) · 829 Bytes
/
Retirement2.java
File metadata and controls
33 lines (23 loc) · 829 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import java.util.*;
public class Retirement2 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.print("How much money will you contribute every year? ");
double payment = in.nextDouble();
System.out.print("Intrest rate in %: ");
double interestRate = in.nextDouble();
double balance = 0;
int year = 0;
String input;
do {
balance += payment;
double intrest = balance * interestRate / 100;
balance += intrest;
year++;
System.out.printf("After year %d, you balance in %,.2f%n", year, balance);
System.out.print("Ready to retire? (Y/N)");
input = in.next();
}
while (input.equals("N"));
}
}