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
thanking you in advance
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;
}
}