Hello,
I am very new to programming and I have hit a stuck point in my code. This is for a mortgage calculator and we have to use the math.pow method. I am getting results, but the results are wrong. The monthly payment is coming out to big.
Here is what it should be:
Enter loan amount: 10000
Enter rate: 4.5
Enter number years: 3
The monthly payment is: $297.47
Here is what I'm getting.
Enter loan amount: 10000
Enter rate: 4.5
Enter number years: 3
The monthly payment is: $566.06
Here is my code. I believe my issue is in the math.pow formula. Can someone help my out?
Scanner in = new Scanner(System.in); // input object
double loanAmount; //user input
double interestRate; // user input
double yearNumber; // user input
double monthlyPayment; // answer to math
double finalPayment; // output
double monthNumber; // year number converted of months
double monthlyRate; // converted intersted rate
System.out.print("Enter loan amount: "); // Shows Line to input loan amount
loanAmount = Double.parseDouble (in.nextLine()); // gets input number
System.out.print("Enter rate: "); // Shows line to input rate amount
interestRate = Double.parseDouble (in.nextLine()); // gets input number
monthlyRate = interestRate * .01; //convert rate into decimal
System.out.print("Enter number years: "); //Shows line to input number of years
yearNumber = Double.parseDouble (in.nextLine()); // gets input number
monthNumber = yearNumber * 12; // total amount of months
monthlyPayment = Math.pow(1+ interestRate,monthNumber) / (Math.pow(1+interestRate, monthNumber)-1);
finalPayment = (loanAmount*monthlyRate*monthlyPayment); // gives the payment
System.out.printf("\nThe monthly payment is: $%.2f", monthlyPayment); // Shows monthly payment