# monthly mortgage payment formula

• 04-21-2011, 11:23 PM
leoshiner
monthly mortgage payment formula
I have written this program to calculate the monthly mortgage payment someone would have to pay but the formula I used at the end for calculating it is wrong and was wondering if anyone has the correct formula

Leon

package pract16;

import javax.swing.JOptionPane;
import java.text.DecimalFormat;

/**
*
* @author Leon
*/
public class Pract16 {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {

DecimalFormat twoDigits = new DecimalFormat("0.00");

String strMoAmt,strMoTerm,strInterest;

double moAmt,moTerm,interest,calcPayment;

strMoAmt=JOptionPane.showInputDialog("Enter Mortgage Amount ");
moAmt=Double.parseDouble(strMoAmt);

strMoTerm=JOptionPane.showInputDialog("Enter Term of Mortgage ");
moTerm=Double.parseDouble(strMoTerm);

strInterest=JOptionPane.showInputDialog("Enter Amount of Interest ");
interest=Double.parseDouble(strInterest);

calcPayment=CP(moAmt,moTerm,interest);

JOptionPane.showMessageDialog(null,"Amount of interest is "+twoDigits.format(calcPayment));

}
public static double CP(double x,double y,double z){

double CP= (x*z)/(1 - Math.pow(1/(1 +z), y * 12));

return CP;

}

}
• 04-22-2011, 12:25 AM
dlorde
A mortgage calculation formula is not a Java problem. If you find the correct formula, we can help you if you have trouble implementing it in Java.
• 04-22-2011, 01:46 PM
leoshiner
ok no problem