-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
26 lines (20 loc) · 861 Bytes
/
Copy pathMain.java
File metadata and controls
26 lines (20 loc) · 861 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
package com.JavaCDMProject;
import java.text.NumberFormat;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Principal: ");
int principal = scanner.nextInt();
System.out.print("Annual Interest Rate: ");
double interestRate = scanner.nextDouble();
System.out.print("Period (Years): ");
byte years = scanner.nextByte();
double rate = (interestRate/12) / 100;
int nPayments = years * 12;
double mortgage = principal * (rate * Math.pow((1 + rate), nPayments) / ((Math.pow((1 + rate), nPayments)) -1));
NumberFormat currency = NumberFormat.getCurrencyInstance();
String result = currency.format(mortgage);
System.out.print("Mortgage: " + result);
}
}