-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExercise1315.java
More file actions
30 lines (24 loc) · 884 Bytes
/
Exercise1315.java
File metadata and controls
30 lines (24 loc) · 884 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
import java.text.DecimalFormat;
public class Exercise1315
{
private static DecimalFormat df = new DecimalFormat("#.##");
public static void main(String[] args)
{
System.out.printf("Monthly Pay\tPaid so far\tLeft to pay\n" );
String sep = "\t\t";
int years = Integer.parseInt(args[0]);
double principle = Double.parseDouble(args[1]);
double rate = Double.parseDouble(args[2]);
double monthlyPay = principle * Math.exp(rate * years);
double paidSoFar = 0;
double totalPay = 12 * years * monthlyPay;
double leftToPay = totalPay ;
System.out.println(totalPay);
System.out.println(0.1 + 0.2);
while (leftToPay > 0.2) {
paidSoFar = paidSoFar + monthlyPay;
leftToPay = totalPay - paidSoFar;
System.out.println(df.format(monthlyPay) + sep + df.format(paidSoFar) + sep + df.format(leftToPay) + sep);
}
}
}