-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMorgageCalculator.java
More file actions
31 lines (17 loc) · 892 Bytes
/
MorgageCalculator.java
File metadata and controls
31 lines (17 loc) · 892 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
import java.util.Scanner;
public class MorgageCalculator {
public static void main (String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter the principal: ");
double principal = input.nextDouble();
System.out.println("Enter the interest rate: ");
double interestRate = input.nextDouble();
System.out.println("Enter the duration in years: ");
double duration = input.nextDouble();
double monthlyRate = (interestRate / 100) / 12;
double months = duration * 12;
double formula = principal * (monthlyRate * Math.pow(1 + monthlyRate, months))
/ (Math.pow(1 + monthlyRate, months) - 1);
System.out.println("Your monthly payment is: a" + formula);
}
}