Solved

# Mortgage Payment Calculator

Posted on 2006-07-18

I am attempting to incorporate a 7 year loan as well as a 15 year loan into the following code and these two loans would have different interest rates than the 30 year loan I have already programmed. I need some assistance on how to incorporate a 7 year loan @ 5.35% and a 15 year loan @ 5.5% into my current code which compiles very nicely:

import java.io.*;

import java.util.Date;

import java.text.DecimalFormat;

public class Mortgage

{

public static void main(String[] args)

{

Date currentDate = new Date();

//Date Constructor

DecimalFormat decimalPlaces = new DecimalFormat("$0.00");

//Declaring Variables

double dPrincipal = 200000.00; //Total Loan or Principal Amount

double dInterest = .0575; //Interest Rate all Payments are Calculated at

double dTerm = 12*30; //Total Term of Loan in Months

double dMonthlyInterest = dInterest/12;

//Declaring Variables

final double dMonthly = dPrincipal * (dMonthlyInterest / (1 - Math.pow(1 + dMonthlyInterest,-dTerm)));

//The above formula calculates and determines the exact monthly payment based upon input

//The following code will display the output of the program

System.out.println("\t\t" + currentDate);

System.out.println("\t\tThe Total Loan Amount is: " + decimalPlaces.format(dPrincipal));

System.out.println("\t\tThe Calculated Interest Rate is: " + dInterest);

System.out.println("\t\tThe Total Number of Monthly Payments is: " + dTerm);

System.out.println("\t\tThe Total Monthly Payment is: " + decimalPlaces.format(dMonthly));

}

}

Any help would be greatly appreciated. Thank you