# Error in Mortgage Calculator (Java)

**URL:** <https://forum.codewithmosh.com/t/error-in-mortgage-calculator-java/15431>\
**Category:** Java\
**Created:** [September 25, 2022, 8:52pm UTC](https://forum.codewithmosh.com/t/error-in-mortgage-calculator-java/15431 "2022-09-25T20:52:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![MoHamandi](https://avatars.discourse-cdn.com/v4/letter/m/e274bd/32.png) [@MoHamandi](https://forum.codewithmosh.com/u/MoHamandi)\
**Post date:** [September 25, 2022, 8:52pm UTC](https://forum.codewithmosh.com/t/error-in-mortgage-calculator-java/15431/1 "2022-09-25T20:52:40Z")

</div>

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;

}

```

}

 ![code error](https://us1.discourse-cdn.com/flex020/uploads/codewithmosh/original/2X/4/490bbe542f7b289f9c526d8f381bb438b0308672.jpeg)

---

<div class="post-metadata">

**Author:** ![jmrunkle](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/jmrunkle/32/3765_2.png) [@jmrunkle](https://forum.codewithmosh.com/u/jmrunkle)\
**Post date:** [September 25, 2022, 9:19pm UTC](https://forum.codewithmosh.com/t/error-in-mortgage-calculator-java/15431/2 "2022-09-25T21:19:29Z")

</div>

This comes up all the time (read some other topics in the Java category). The parameter names are added by the IDE, Mosh is not literally typing "prompt: " that is just being added by the IDE to help you to read the code. If you remove all of the "parameterName: " stuff your code should work. For example:

```java
int principal = (int) readNumber( "Principal: ", 1000, 1_000_000);

```

---

<div class="post-metadata">

**Author:** ![MoHamandi](https://avatars.discourse-cdn.com/v4/letter/m/e274bd/32.png) [@MoHamandi](https://forum.codewithmosh.com/u/MoHamandi)\
**Post date:** [September 26, 2022, 2:59am UTC](https://forum.codewithmosh.com/t/error-in-mortgage-calculator-java/15431/3 "2022-09-26T02:59:59Z")

</div>

thank you for taking the time to explain
