Mortgage Calculator

will u please put the whole Javascript of the mortgage calculator here
I know its in the video but still
My reason:- when I put “/” at the ending it says its the illegal start of expression

sry if this is silly

What do you mean “/”? explain me

import java.text.NumberFormat;
import java.util.Scanner;
public class main
{
public static void main(String[]args)
{
final byte MONTHS_IN_YEAR = 12;
final byte PERCENT = 100;

Scanner scanner = new Scanner(System.in);

System.out.println("Principal: ");
    int principal = scanner.nextInt();

System.out.println("Annual Interest Rate");
     float annualInterest = scanner.nextFloat();
      float monthlyInterest = annualInterest / PERCENT / MONTHS_IN_YEAR;

System.out.println("Period (Years): ");
     byte years = scanner.nextByte();
     int numberOfPayments = years * MONTHS_IN_YEAR;

double mortgage = principal*(monthlyInterest * Math.pow(1 + monthlyInterest, numberOfPayments))/(Math.pow(1 + monthlyInterest, numberOfPayments) - 1);

String mortgageFormatted = NumberFormat.getCurrencyInstance();
System.out.print("Mortgage: " + mortgageFormatted);






 }
 
 
 }

will u please let it run it would mean a lot to me

thx bro for helping but i got the program run

Hey! :smile: your code does not run because you need to add in the mortgageFormatted line the mortgage, like this:

String mortgageFormatted = NumberFormat.getCurrencyInstance().format(mortgage);
        System.out.println("Mortgage: "+mortgageFormatted);

Try it and let me know if it works for you.

This is the code, try it and let me know if it works for you :grin:

public static void main(String[] args) {
        final byte MONTHS_IN_YEAR = 12;
        final byte PERCENT = 100;

        Scanner scanner = new Scanner(System.in);

        System.out.print("Principal: ");
        int principal = scanner.nextInt();

        System.out.print("Annual Interest Rate: ");
        float annualInterest = scanner.nextFloat();
        float monthlyInterest = annualInterest / PERCENT / MONTHS_IN_YEAR;

        System.out.print("Period (Years): ");
        byte years = scanner.nextByte();
        int numberOfPayments = years * MONTHS_IN_YEAR;

        double mortgage = principal *
                (monthlyInterest * Math.pow(1+monthlyInterest,numberOfPayments))
                /(Math.pow(1+monthlyInterest,numberOfPayments)-1);

        String mortgageFormatted = NumberFormat.getCurrencyInstance().format(mortgage);
        System.out.println("Mortgage: "+mortgageFormatted);
    }
1 Like

Thanks i needed this ( .format(mortgage):wink: :slight_smile:
You don’t see it in the video and i don’t find the source code from Mosh.
Greetz

No need for calculating, your loan 1$ and return 2$ :slight_smile: