Java School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a Java Expert!

Join 300,492 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,832 people online right now. Registration is fast and FREE... Join Now!




Assistance with GUI Mortgage Calculator

 

Assistance with GUI Mortgage Calculator, problems with amoritization table and calculation

A_town_clown

14 Nov, 2007 - 11:05 PM
Post #1

New D.I.C Head
*

Joined: 11 Nov, 2007
Posts: 3


My Contributions
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

CODE

/*
* 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();
  }
}
}



User is offlineProfile CardPM
+Quote Post


Martyr2

RE: Assistance With GUI Mortgage Calculator

16 Nov, 2007 - 03:10 PM
Post #2

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 7,246



Thanked: 820 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
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. smile.gif
User is offlineProfile CardPM
+Quote Post

A_town_clown

RE: Assistance With GUI Mortgage Calculator

20 Nov, 2007 - 12:26 AM
Post #3

New D.I.C Head
*

Joined: 11 Nov, 2007
Posts: 3


My Contributions






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!


User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/8/09 04:29AM

Live Java Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month