I have already turned this so my grade will off anyway but I just need to know. I cannot get the right figure for this calculation, here is what I have and it gives me the wrong calculation of 7178. when its supossed to be 1167. Any help would greatly appreciated. The bolded text is what is wrong.

class MortgageCalculatorx
{
//Program Variables
public static void main(String[] args)
{
double Loan = 200000; // *$200,000 Loan
int Term = 360; //*360 Months
double InterestRate = .0575; //*5.75% interest rate
double Interest = Loan * InterestRate; // calculate interest
double Payment = Loan * InterestRate / 1 - (InterestRate + 1) - 12 * Term; // monthly payment
//Output
System.out.println ();
System.out.println (" This is my mortgage calculator" );
System.out.println ();
System.out.println (" Your loan amount is $"+ Loan); //*prints loan amount
System.out.println ();
System.out.println (" Your interest rate is $"+ InterestRate); //*prints interest rate
System.out.println ();
System.out.println (" Your payment time is " + Term/12 + " years"); //*prints loan term
System.out.println ();
System.out.println (" Your monthly payment is $"+ Payment); //*prints monthly payment
System.out.println ();
}
}

Recommended Answers

All 10 Replies

I, personally, don't know the right formula for mortgage rate calculations, so please provide the formula you were to use as presented in your assignment instructions.

In any case, when you get the wrong number, then the problem is usually that you have entered the formula wrong, which is the reason I want to see how it was presented to you in your assignment.

Bracklets is what you missing in your calculation in first place as your line of code
double Payment = Loan * InterestRate / 1 - (InterestRate + 1) - 12 * Term;
Java's rules of operator precedence are

  1. Multiplication, division and reminder operations are applied first. If an expression contains several such operations, the operators are applied from left to right. Miltiplication, division and remainder have the same level of precedence
  2. Addition and subtraction operations are applied next. If an expresion contains several such operations, the operators are applied from left to right. Addition and subtraction operations have the same level of precedence
  3. If there are any bracklets, calculate first content of braclets using the first two rules and then run calculation on reminding expresion be following first two rules

so you expresion is
Payment = Loan * InterestRate / 1 - (InterestRate + 1) - 12 * Term
replace variables with values
Payment = 200000 * 0.0575 / 1 - ( 0.0575 + 1 ) - 12 * 360
Braclet first
Payment = 200000 * 0.0575 / 1 - 1.0575 - 12 * 360
Multiplications and division
Payment = 11500 / 1 - 1.0575 - 12 * 360
Payment = 11500 - 1.0575 - 12 * 360
Payment = 11500 - 1.0575 - 4320
Payment = 7178 (plus some reminder)

Your expresion is also not realy clear. Why 1 - (InterestRate + 1) ?
Thats gives only negative InterestRate. You could do it with simple -InterestRate

I, personally, don't know the right formula for mortgage rate calculations, so please provide the formula you were to use as presented in your assignment instructions.

In any case, when you get the wrong number, then the problem is usually that you have entered the formula wrong, which is the reason I want to see how it was presented to you in your assignment.

Ops so sorry, here it is- Write a program that calculates and displays the mortgage payment amount given the amount of the mortgage, the term of the mortgage, and the interest rate of the mortgage. In the first iteration of the program, hard code the principal = $200,000, the term = 30 years, and the annual interest rate = 5.75%-

That, however, is not the formula. I realise now, that the assignment probably did not have the formula in it, and it assumed you knew the formula. Unfortunately, I do not know the formula, can you post that know please. (i.e. Principal * Interest * Term / ......)

Thanks there is some good help, The problem I have is that I am not sure what the formula is supposed to be, I have not have any exposure to this and this class is pretty fast pace. Here is what it is based on

payment = [$200,000(1 + .00575)360 x .00575] / [(1 + .00575)360 - 1] = $1167

But I dont know hwo to put that into code.

Thanks there is some good help, The problem I have is that I am not sure what the formula is supposed to be, I have not have any exposure to this and this class is pretty fast pace. Here is what it is based on

payment = [$200,000(1 + .00575)360 x .00575] / [(1 + .00575)360 - 1] = $1167

But I dont know hwo to put that into code.

You missing operation markers between 200000 and bracklet of (1+0.00575) plus other places, interest is less then 0.5% acording to this, I do not understand why do you apply interest to number of months ( 360 * 0.00575) and last part what is point to take one of final calculation. That will be last step to your output. Shouldn't be like this (1+0.00575)*(360-1)? So if I take empty places are multiplication then code will be like this

payment = ( 200000 * (1 + 0.00575) * 360 * 0.00575) / ((1 + 0.00575) * 360 -1)

Using your variables it is as such:

double Payment = Loan * (1 + (InterestRate / 10)) * term * (InterestRate / 10) / (((InterestRate / 10) + 1) * Term - 1);

But I don't know if that is the right formula as it results in 1153 not 1167.

It's always ( InterestRate / 10 ) InterestRate 0.0575, but your formula states 0.00575

Well, the line of code provided to you directly implements the formula you provided. If the answer is wrong, the formula is wrong. I'm sorry, but the calculation, given the formula provided, is correct. Do it yourself using a scientific calculator (so you can enter the parens) and you will see for yourself. Check the formula again.

I really appreciate all the help, I'll see what is going on and let you know.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.