Mortgage Formula

My Formula do not work

Page 1 of 1

1 Replies - 1368 Views - Last Post: 21 July 2009 - 07:07 AM Rate Topic: -----

#1 jojos   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 21-July 09

Mortgage Formula

Posted 21 July 2009 - 06:31 AM

Hello all,

First thanks in advance for taking the time to open what has had a number of post by others. I have read other postings; however, have not seen a reply that I can relate/understand. The goal of the applet code I am working on shows the monthly mortgage payment based on sum, term & interest. I have tried a number of formulas with no luck. Currently the formula are commented out, if anyone can review some of the formulas a point me in the right direction as to what I may be doing wrong it would be a great help. Thanks in advance.

import java.applet.*;
import java.awt.*;
import java.awt.event.*;

public class MortgagePayment extends Applet implements ActionListener
{
	//decalre variables
	//Image logo; //declare an Image object
	int mortgageSum, mortgageTerm, mortgagePayment, mortgageInterest;
	//double mortgagePayment;

	//construct components
	Label companyLabel = new Label("Joey Berrys Mortgage Payment Calculator");

	Label loanLabel = new Label("Enter Mortgage Total in Dollars:");
		TextField loanField = new TextField(10);

	Label yearsLabel = new Label ("Enter Mortgage Total Payment Years:");
		TextField yearsField = new TextField(10);

	Label interestLabel = new Label ("Enter Mortgage Interest:");
		TextField interestField = new TextField(10);

	Button calcButton = new Button("Calculate");
	Label outputLabel = new Label("Click Calculate Button To Display Mortgage Monthly Payment");

	public void init()
	{
		setForeground(Color.blue);
		add(companyLabel);
		add(loanLabel);
		add(loanField);
		add(yearsLabel);
		add(yearsField);
		add(interestLabel);
		add(interestField);
		add(calcButton);
		calcButton.addActionListener(this);
		add(outputLabel);
		//logo = getImage(getDocumentBase(), "logo.gif");
	}

	public void actionPerformed(ActionEvent e)
	{

	mortgageSum = Integer.parseInt(loanField.getText());
	mortgageTerm = Integer.parseInt(yearsField.getText());
	mortgageInterest = Integer.parseInt(interestField.getText());

	//preform payment calculations

	//double mortgagePayment =(mortgageSum() * (mortgageInterest[1]/100/12)) / (1 - Math.pow(1/(1 + (mortgageInterest[1]/100/12)),mortgageTerm[1]*12));
	//double Payment =(loanAmount() * (intRate[1]/100/12)) / (1 - Math.pow(1/(1 + (intRate[1]/100/12)),loanTerm[1]*12));

	//mortgagePayment = (mortgageSum*mortgageInterest*Math.pow(1+mortgageInterest, mortgageTerm)/(Math.pow(1+mortgageInterest, mortgageTerm))-1);
	//mortgagePayment = (mortgageSum*mortgageInterest / (1-Math.pow(1/(1+mortgageInterest),mortgageTerm)));
	//monthlyPayment = (principal*interestRate*Math.pow(1+interestRate, term)/(Math.pow(1+interestRate, term))-1);
	//mortgagePayment = (mortgageSum * mortgageInterest * Math.pow(1+mortgageInterest, mortgageSum)/(Math.pow(1+mortgageInterest, mortgageSum))-1);

	//Display Output
	outputLabel.setText("The Monthly Mortgage Payment " + mortgagePayment + ".");
	}

	public void paint(Graphics g)
	{
		g.drawImage(logo,125,160,this);
	}
}



Is This A Good Question/Topic? 0
  • +

Replies To: Mortgage Formula

#2 William_Wilson   User is offline

  • lost in compilation
  • member icon

Reputation: 207
  • View blog
  • Posts: 4,812
  • Joined: 23-December 05

Re: Mortgage Formula

Posted 21 July 2009 - 07:07 AM

My personal opinion is that you are trying to do too much on one line. Try breaking down what you are trying to accomplish and do each step one line at a time. This will allow you to see if the values are correct at each step before moving on to the next step of the formula.
When you have that many brackets it becomes easy to make a mistake.

Ex:
mortgagePayment = mortgageSum / 12;
mortgagePayment = mortgagePayment *mortgageInterest;
//etc.



I am confused as to why mortgageSum is a variable sometimes and a method others as I do not see the method you are trying to call.

If you need more help after trying that, post the new code. We will also need to know more about the formula you are trying to write. Do you have it written in words or as a math formula not in programming?

Also, do you have a test case and the expected output? This will help in discovering what may be right and what might be wrong.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1