-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCh3Ex5.java
More file actions
29 lines (26 loc) · 715 Bytes
/
Ch3Ex5.java
File metadata and controls
29 lines (26 loc) · 715 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
//Calculates Months to payoff a loan
public class Ch3Ex5
{
public static void main(String[] args)
{
double overallCost = 1000;
double monthlyPayment = 50;
double monthlyInterest = .015;
int monthCount = 0;
double overallInterest=0;
while (overallCost>0)
{
double interest = (overallCost * monthlyInterest);
overallInterest += interest;
if (monthlyPayment>overallCost)
{
double totalPayment = overallCost + interest;
}
double principal = (monthlyPayment -interest);
overallCost= (overallCost - principal);
monthCount ++;
}
System.out.println("Number of Months to payoff: "+ monthCount);
System.out.printf("Total Interest Paid: $%.2f",overallInterest);
}
}