import java.sql.SQLOutput;
import java.text.NumberFormat;
import java.util.Scanner;
public class ayushe {
public static void main(String args) {
final byte MONTHS_IN_YEAR = 12 ;
final byte PERCENT = 100 ;
int principal = 0;
float monthlyInterest = 0 ;
int numberOfPayments = 0 ;
Scanner scanner = new Scanner(System.in);
while (true) {
System.out.println("Principal: ");
principal = scanner.nextInt();
if (principal >= 1000 && principal <= 1_000_000)
break;
System.out.println("Enter a value between 1000 and 100000");
}
while (true) {
System.out.println("Annual Interest Rate: ");
float annualInterest = scanner.nextFloat();
if (annualInterest >= 1 && annualInterest <= 30) {
monthlyInterest = annualInterest / PERCENT / MONTHS_IN_YEAR;
break;
}
System.out.println("Enter a value between 1 and 30");
}
while (true) {
System.out.println("Period (Years): ");
byte years = scanner.nextByte();
if ( years >= 1 && years <= 30) {
numberOfPayments = years * MONTHS_IN_YEAR;
break;
}
System.out.println("Enter a value between 1 and 30 ");
}
double mortgage = principal
* (monthlyInterest * Math.pow(1 + monthlyInterest) / (Math.pow(1 + monthlyInterest, numberOfPayments));
String mortgageFormatted = NumberFormat.getCurrencyInstance().format();
System.out.println("MOrtgage: " + mortgageFormatted);