Ok , I am doing an assignment for a mortgage calculator in JAVA. The assignment is to write the code first, then enter into JAVA to execute. I am all new to this so……Here is my code and it will not execute. I am lost as lost can be. Any help will be appreciated.
public class MortageCalculator {
public static void main(String [] args) {
//declare variables
double interestRate=.0575;
int amount=200000;
int term=30;
double monthlyInterestRate=interestRate / 12;
int totalMonths=term * 12;
double payment=amount * (1-(Math.pow((1+monthlyInterestRate ),(-totalMonths))));
//display payment amount
System.out.println("The monthly payment for your mortage is" + payment);
}
}
Here is the info:
Formula for mortgage payment calculation:
a = [P(1 + r)nr]/[(1 + r)n - 1] — where P is the principal amount, r is the interest rate and n is the term in years.
Formulas to calculate the monthly payment and balance:
interestRate = .0575;
amount = 200000;
term = 30;
monthlyInterestRate = interestRate / 12;
totalMonths= term * 12;
payment = amount * monthlyInterestRate / (1-(Math.pow((1+monthlyInterestRate ),(-totalMonths))));
Formulas to calculate the amortization:
interestPaid = loanBalance * montlyInterestRate;
principalPaid = payment – interestPaid;
loanBalance = loanBalance – principalPaid;
//loanBalance is a running number, the initial value is equal to amount
I wrote this in notepad.
I tried to execute your code and it works fine (I’m not sure about the formula and all but wrt programming, it’s fine).
Just as a check:
name the file as MortageCalculator.java
build as : javac MortageCalculator.java
execute as : java MortageCalculator
For ease in debugging, you can use a good IDE such as Eclipse. or at least notepad++
I tried to execute your code and it works fine (I’m not sure about the formula and all but wrt programming, it’s fine).
Just as a check:
name the file as MortageCalculator.java
build as : javac MortageCalculator.java
execute as : java MortageCalculator
For ease in debugging, you can use a good IDE such as Eclipse. or at least notepad++
References :