Assistance with GUI Mortgage Calculator

problems with amoritization table and calculation

Page 1 of 1

2 Replies - 3146 Views - Last Post: 20 November 2007 - 01:26 AM Rate Topic: -----

#1 A_town_clown  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 11-November 07

Assistance with GUI Mortgage Calculator

Post icon  Posted 15 November 2007 - 12:05 AM

Hello people, I am here to enlist the help of those with a greater knowledge of programming than myself. I am a newbie to the programming scene and this is my first program. While I have somewhat of a grasp on simple things, can some one please assit me...My first problem is that I can not get the calculations correct. I've tried several formula's but thy all come out the same way, something like this: 4655.690405738445. Also, I have the slightest clue as to how to list the loan balance and interest paid for each payment over the term of the loan.

Thanks for your input/assistance.
Charles

 /*
 * Morgage Application.  Calcualte the payments based on the amounts, terms and
 * interest rates.  Show a list of the balance and the interest paid.
 * Title	 WK 3 Calculator
 * author	Charles I. Clay
 * Date	  11/10/07
 * version   1.0
 */

//Imports
import java.awt.*;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

//Create GUI fields, labels, and buttons
public class WK3Calculator extends JFrame implements ActionListener {
private JPanel panelAdder;
private JLabel labela;
private JLabel labelt;
private JLabel labelr;
private JTextField textFieldAmount;
private JTextField textFieldTerm;
private JTextField textFieldRate;
private JTextField textFieldResult;
private JButton buttonCalc;

public WK3Calculator() {
  initComponents();
  setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  setVisible(true);
  pack();

  // Add Listeners
  buttonCalc.addActionListener(this);
}

public void initComponents() {
 //Initialization of Components
 panelAdder = new JPanel();
 labela = new JLabel("Amount of Loan");
 textFieldAmount = new JTextField();
 labelt = new JLabel("Term of Loan");
 textFieldTerm = new JTextField();
 labelr = new JLabel("Interest Rate");
 textFieldRate = new JTextField();
 textFieldResult = new JTextField();
 buttonCalc = new JButton("Calculate");

 //Set Attributes
 textFieldResult.setEditable(false);
 textFieldResult.setColumns(8);
 textFieldAmount.setColumns(6);
 textFieldTerm.setColumns(2);
 textFieldRate.setColumns(2);

 Container contentPane = getContentPane();
 contentPane.setLayout(new FlowLayout());

 //Addition of components to the panel
 panelAdder.add(labela);
 panelAdder.add(textFieldAmount);
 panelAdder.add(labelt);
 panelAdder.add(textFieldTerm);
 panelAdder.add(labelr);
 panelAdder.add(textFieldRate);
 panelAdder.add(buttonCalc);
 panelAdder.add(textFieldResult);

 contentPane.add(panelAdder);
}

public static void main(String[] args) {
  WK3Calculator frame = new WK3Calculator();
}

private void setResultValue() {
   double amount = Double.parseDouble (textFieldAmount.getText());
   double term = Integer.parseInt(textFieldTerm.getText());
   double rate = Double.parseDouble(textFieldRate.getText()) / 100.;
   double result = amount * ( rate * Math.pow ( ( 1 + rate ), term ) ) / ( Math.pow( ( 1 + rate ), term ) - 1 );

   textFieldResult.setText(Double.toString(result));
}

public void actionPerformed(ActionEvent event) {
  System.out.println("Action Button");
  String command = event.getActionCommand();
  if (command == "Calculate") {
	  setResultValue();
  }
}
}




Is This A Good Question/Topic? 0
  • +

Replies To: Assistance with GUI Mortgage Calculator

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4399
  • View blog
  • Posts: 12,255
  • Joined: 18-April 07

Re: Assistance with GUI Mortgage Calculator

Posted 16 November 2007 - 04:10 PM

For the formula and even an example of using this project with a GUI you can check out my advice on the following thread...

Mortgage Calculator With GUI

There I show superczech how to fix his problems with the calculation. The project he created is one of the nicer ones so if you want to make an example with it, just copy and paste and run it. Then you will be able to tinker with it and see how the calculation works across multiple time spans with multiple interest rates.

I am sure this thread will help you greatly. :)
Was This Post Helpful? 0
  • +
  • -

#3 A_town_clown  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 11-November 07

Re: Assistance with GUI Mortgage Calculator

Posted 20 November 2007 - 01:26 AM

Martyr2,
I know this may be along shot, but I've run into bigger problems and would like some assistance if you have time. I had to give up on fixing the calculations because my assignment was due. I would greatly appreciate some assistance with figuring out this piece of the pie. I had to create a manual/automatic GUI calculator, and unfortunately, when I press one of the fixed calculations buttons, it disappears on me....I am beyond lost...PLEASE HELP!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1