DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Mortgage Payment Calculator In Java

  • submit to reddit
        This below Java code will help you to find the monthly payment for the Mortgage payment. Here the array term has months required to payoff the mortgage and array rates interest rate for the mortgage and loan has the loan amount value. This code will perform mortgage comparison

import java.math.*;
import java.text.*;
class MortgageCalculator {
public static void main(String arguments[]) {
//Program Variables using array
double []terms = {84,180,360};//Mortgage Loan Term
double []Rates = {0.0535, 0.055, 0.0575};//Mortgage Loan's Interest Rate
double loan = 200000;//Loan Amount

double term, interestRate; //Temporary variables to make things generic and clearer

DecimalFormat df = new DecimalFormat("$###,###.00"); //Formatting the output

//for each term and Rate starting from the first location of each array terms[] and Rates[]
for (int i=0;i<terms.length;i++){
//Calculates the Payment per month to be paid under mortgage scheme One
interestRate=Rates[i]; //take value from the array Rates[] to a temporary variable
term=terms[i]; //take value from the array terms[] to a temporary variable
double monthlyRate = (interestRate/12); //derive the monthly interest rate
//calculate the discount factor
double discountFactor = (Math.pow((1 + monthlyRate), term) -1) / (monthlyRate * Math.pow((1 + monthlyRate), term));
double payment1 = loan / discountFactor; //calculate payable amount per month
//Output for mortage scheme One
System.out.println("The Loan amount is:"+df.format(loan)+"\n");
System.out.println("The intrest rate is:"+interestRate*100+"%");
System.out.println("The term of the loan is:"+term/12+" years.");
System.out.println("Monthly Payment Amount: " + df.format(payment1)+"\n");
For online mortgage comparison <i><a href="">Mortgage Payment Calculator</a></i>    


Noe Samuhel replied on Thu, 2013/05/09 - 6:16am

Great program, I have always been confused regarding mortgage calculators. My friend John Studzinski always knows what to do when it comes to different software and codes, but I, for one, am clueless without the manuals.