Java Mortgage calculator help.?
Can someone help me flesh out the details of this? I need to make a mortgage calculator in java does the following
The user will be asked to enter to the amount of the mortgage loan, the term in years of the mortgage, and an annual interest rate. The amount of the mortgage loan shall be greater than 0 and not exceed 10,000,000 dollars. The minimum term for the loan is five years, with a maximum of 30 years. In addition to the user being able to supply the mortgage information the application will display three of the most commonly used mortgages and the user shall be able to select these mortgages instead of supplying the mortgage information. Once the user has provided the mortgage information, the program shall calculate the monthly mortgage payment and the amortization table for the life of the mortgage. For each month the amortization table shall display the loan period, loan balance, principal balance, interest balance, principal paid and interest paid.
Here is mortgage payment formula.
PMT = (PV x IR) / (1 – (1 + IR)^-NP)
Where:
PMT = Monthly Payment
PV = Principle Value (amount of loan)
IR = Interest Rate, by month
NP = Note Period, or mortgage term in months
IR = apr/100/12
NP = term * 12
if Apr > 0 AND APR <= 100 then
PMT = (Principal * IR)/(1-(1 + IR)-np)
else if Apr = 0
PMT = Principal/NP
end if
I need help I am not so good with Java. As long as i get the calculator part of this done i think i can handle the rest.
February 1st, 2010 at 12:12 pm
import java.util.Scanner;
class MortgageCalculator2 {
public MortgageCalculator2() {
intro();
}
public void mess(String s) {
System.out.printf("%s%n", s);
}
public void messIn(String s) {
System.out.printf("%s > ", s);
}
public void intro() {
Scanner sc = new Scanner(System.in);
boolean run = true;
mess("——————————————");
mess("Mort Especi\u00e2l Waresofto");
mess("if we can’t float the loan, the gov’t will");
mess("——————————————\n");
while (run) {
String[] args = new String[3];
messIn("enter Principal Amount: ");
args[0] = sc.nextLine();
messIn("enter Note Period (Years)");
args[1] = sc.nextLine();
messIn("enter APR example: 9.55");
args[2] = sc.nextLine();
String pmt = calculation(args);
mess("\n");
mess(pmt);
mess("do another one?");
if (sc.nextLine().
equalsIgnoreCase("q")) {
run = false;
}
}
}
public static void main(String[] args) throws Exception {
new MortgageCalculator2();
}
private String calculation(String[] args) {
float pv = Float.valueOf(args[0]);
int term = Integer.valueOf(args[1]);
float apr = Float.valueOf(args[2]);
// double ir = apr / 100 / 12;
double ir = apr / 12 ;
double np = term *12;
System.out.printf("interest monthly: %2.2f%%", ir);
double payNum = (pv * ir) / ( 1 – (1+ir)-np);
return String.format( "Monthly Payment: $%6.2f",payNum);
}
}
I don’t have faith in the teacher’s formula. This is not how I would do a mortgage program. But, maybe this will get you going.