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