-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathComputeLoan.java
More file actions
34 lines (27 loc) · 1.24 KB
/
ComputeLoan.java
File metadata and controls
34 lines (27 loc) · 1.24 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
import java.util.Scanner;
/**
* Created by Melissa on 14/04/2017.
*/
public class ComputeLoan {
public static void main(String[] args) {
// Create a Scanner Object
Scanner input = new Scanner(System.in);
// Enter annual interest rate in percentage, e.g., 7.25%
System.out.print("Enter annual interest rate, e.g., 7.25%: ");
double annualInterestRate = input.nextDouble();
// Obtain monthly interest rate
double monthlyInterestRate = annualInterestRate / 1200;
// Enter number of years
System.out.print("Enter number of years as an integer, e.g., 5: ");
int numberOfYears = input.nextInt();
// Enter loan amount
System.out.print("Enter loan amount, e.g., 120000.95: ");
double loanAmount = input.nextDouble();
// Calculate payment
double monthlyPayment = loanAmount * monthlyInterestRate / (1 - 1 / Math.pow(1 + monthlyInterestRate, numberOfYears * 12));
double totalPayment = monthlyPayment * numberOfYears * 12;
// Display results
System.out.println("The monthly payment is $" + (int)(monthlyPayment * 100) / 100.0);
System.out.println("The total payment is $" + (int)(totalPayment * 100) / 100.0);
}
}