# Thread: monthly mortgage payment formula

1. Member
Join Date
Oct 2010
Posts
28
Rep Power
0

## 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;

}

}

2. Senior Member
Join Date
Jun 2008
Posts
339
Rep Power
5
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.

3. Member
Join Date
Oct 2010
Posts
28
Rep Power
0
ok no problem

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•