-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFerrariCarPayments.java
More file actions
43 lines (31 loc) · 1.37 KB
/
Copy pathFerrariCarPayments.java
File metadata and controls
43 lines (31 loc) · 1.37 KB
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
33
34
35
36
37
38
39
40
41
// FerrariCarPayments.java
// Author: Te-Feng(Dylan) Pan
// Last Modified: 01/22/2013
// --------------------------
// This program reads in an amount owed and monthly payments
// and prints out monthly interest paid, amount paid to principal
// and new balance to the screen.
import java.util.Scanner;
import java.text.DecimalFormat;
public class FerrariCarPayments
{
public static void main(String[] args)
{
double monthlyPayment, outBalance, interest;
interest = 0.0245;
Scanner keyboard = new Scanner(System.in);
System.out.println("Please enter the amount you owe:");
outBalance = keyboard.nextDouble();
System.out.println("Please enter your monthly payment amount:");
monthlyPayment = keyboard.nextDouble();
double monthlyInterestPaid = (interest / 12) * outBalance;
//double.format("%.2f", monthlyInterestPaid);
DecimalFormat doubleValue = new DecimalFormat("0.00");
String formattedValue = doubleValue.format(monthlyPayment);
double amountPaidPrincipal = monthlyPayment - monthlyInterestPaid;
double newBalance = outBalance - amountPaidPrincipal;
System.out.printf("The amount of the payment that goes to interest: %.2f\n", monthlyInterestPaid);
System.out.printf("The amount of the payment that goes towards the amount owed: %.2f\n", amountPaidPrincipal);
System.out.printf("The new balance owed: %.2f\n", newBalance);
}
}