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

}

}

}

[5153 byte] By [ustridenta] at [2007-11-26 12:20:40]
# 1

> 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!!

First of all, what is the mortgage formula?

tymer99a at 2007-7-7 15:11:09 > top of Java-index,Archived Forums,Socket Programming...
# 2
These websites are what I used to get the formula and mesh it in with the program. http://www.mtgprofessor.com/formulas.htm http://mathforum.org/library/drmath/view/54623.html
ustridenta at 2007-7-7 15:11:09 > top of Java-index,Archived Forums,Socket Programming...
# 3
On this line, you need to compare Strings using .equals, not "==":if (command == "Calculate") { http://access1.sun.com/FAQSets/newtojavatechfaq.html#9
doremifasollatidoa at 2007-7-7 15:11:09 > top of Java-index,Archived Forums,Socket Programming...