Hi, I’m trying to run the program but I see errors under (prompt: "Principal: ", min: 1000, max: 1_000_000); saying that I need to create local variable prompt, min and max and even if I create I get errors under : signs, can someone please check the code
package com.example.calculator;
import java.text.NumberFormat;
import java.util.Scanner;
public class main {
public static void main(Stringargs){
int principal = (int) readNumber( prompt: "Principal: ", min: 1000, max: 1_000_000);
float annualInterest = (float) readNumber( prompt: "Annual Interest Rate: ", min: 1, max: 30);
byte years = (byte) readNumber( prompt: "Period (Years): ", min: 1, max: 30);
double mortgage = calculateMortgage(principal,annualInterest, years);
String mortgageFormatted = NumberFormat.getCurrencyInstance().format(mortgage);
System.out.println("Mortgage: " + mortgageFormatted);
}
public static double readNumber(String prompt, double min, double max) {
Scanner scanner = new Scanner(System.in);
double value;
while (true) {
System.out.println(prompt);
value = scanner.nextFloat();
if (value >= min && value <= max)
break;
System.out.println("Please enter a value between " + min + " and " + max);
}
return value;
}
public static double calculateMortgage(int principal,
float annualInterest,
byte years) {
final byte MONTHS_IN_YEAR = 12;
final byte PERCENT = 100;
int NumberOfPayments = years * MONTHS_IN_YEAR;
float MonthlyInterestRate = annualInterest / PERCENT / MONTHS_IN_YEAR;
double MonthlyMortgage = principal * (MonthlyInterestRate * Math.pow(1+MonthlyInterestRate,
NumberOfPayments)) / (Math.pow(1+MonthlyInterestRate, NumberOfPayments) -1);
return MonthlyMortgage;
}
}