Need help with the text output here... kinda a newbie..
Alright the problem I am having is with the output of this program. It does not appear to calculate the mortgage formula correctly and outputs some other data that does not make any sense. here is the code. Any help on this matter would be great!!
import java.awt.*;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
publicclass Calculatorextends JFrameimplements 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 Calculator(){
initComponents();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
pack();
// Add Listeners
buttonCalc.addActionListener(this);
}
publicvoid initComponents(){
//Initialize Components
panelAdder =new JPanel();
labela =new JLabel("Amount");
textFieldAmount =new JTextField();
labelt =new JLabel("Term");
textFieldTerm =new JTextField();
labelr =new JLabel("Rate");
textFieldRate =new JTextField();
textFieldResult =new JTextField();
buttonCalc =new JButton("Calculate");
//Set Object Attributes
textFieldResult.setEditable(false);
textFieldResult.setColumns(8);
textFieldAmount.setColumns(6);
textFieldTerm.setColumns(2);
textFieldRate.setColumns(2);
Container contentPane = getContentPane();
contentPane.setLayout(new FlowLayout());
//Lets add the 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);
}
publicstaticvoid main(String[] args){
Calculator frame =new Calculator();
}
privatevoid 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 );
double result = (amount*((rate/12)/(1-Math.pow((1+(rate/12)),-(term*12)))));
textFieldResult.setText(Double.toString(result));
}
publicvoid actionPerformed(ActionEvent event){
System.out.println("Action Button");
String command = event.getActionCommand();
if (command =="Calculate"){
setResultValue();
}
}
}

