result = (num1 * num2);
//(1 - Math.pow(1/ (1 + num2), num3 * 12));
I used the second part of the equation as documentation statement but the original format should be:
result = (num1 * num2)/(1 - Math.pow(1/ (1 + num2), num3 * 12));
I get a compile error on the division sign and I just do not understand what I'm doing wrong.
Loan amount times Interest rate, number of years for amortizing. Display monthly payment in Monthly payment field.
Any help would be greatly appreciated.
Thank you,
Phil
/**
* Mortgage Calculator- Complete Change Request #4 in Service Request SR-mf-003.
* Insert comments in the program to document the program. Attach a design flow chart
* to the source code of the program.
*
* Change Request #4: Write the program in Java (with a graphical user interface)
* and have it calculate and display the mortgage payment amount from user input of
* the amount of the mortgage, the term of the mortgage, and the interest rate of the
* mortgage. Allow the user to loop back and enter new data or quit.
* Please insert comments in the program to document the program.
*
* Author Phil Grabowski
* University of Phoenix
* PRG421 Java Programming II
* Course Date 2/24/09 End Date 3/30/09
* Instructor Yining Li
*/
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
public class MortgageCR41 extends JFrame implements ActionListener {
public MortgageCR41()
{
Container content = this.getContentPane();
content.setBackground(Color.white);
content.setLayout(new FlowLayout());
content.add(new JButton("Loan Amount"));
content.add(new JTextField(" "));
content.add(new JButton("Interest Rate"));
content.add(new JTextField(" "));
content.add(new JButton("Term in Years"));
content.add(new JTextField(" "));
content.add(new JButton("Montly Payment"));
content.add(new JTextField(" "));
}
private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {
}
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0);
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
jTextField1.setText("");
jTextField2.setText("");
jTextField3.setText("");
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
float num1, num2, num3, result;
// num1 = Amount of loan
// num2 = Interest of Loan
// num3 = Term in years
num1 = Float.parseFloat(jTextField1.getText());
num2 = Float.parseFloat(jTextField2.getText());
num3 = Float.parseFloat(jTextField3.getText());
result = (num1 * num2);
//(1 - Math.pow(1/ (1 + num2), num3 * 12));
jTextField3.setText(String.valueOf(result));
}
public static void main(String args[]) {
// JFrame f = new JFrame("Mortgage Calculator CR#4");
MortgageCR41 f = new MortgageCR41();
f.setSize(300, 250);
f.setVisible(true);
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JPanel jPanel1;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
private javax.swing.JTextField jTextField3;
// End of variables declaration
JButton myButton = new JButton("Calculate");
JCheckBox myCheckBox = new JCheckBox("Reset Fields");
// Clear all fields in Jbuttons
JTextArea myText = new JTextArea("Please enter the fields and click calculate");
JPanel Panel = new JPanel();
JPanel holdAll = new JPanel();
{
Panel.setLayout(new FlowLayout());
Panel.add(myCheckBox);
Panel.add(myButton);
holdAll.setLayout(new BorderLayout());
holdAll.add(Panel, BorderLayout.NORTH);
holdAll.add(myText, BorderLayout.CENTER);
getContentPane().add(holdAll, BorderLayout.CENTER);
myButton.addActionListener(this);
myCheckBox.addActionListener(this);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == myButton)
myText.setText("Thank you");
else if (e.getSource() == myCheckBox)
myText.setText("Fields Cleared" +
myCheckBox.isSelected());
else
myText.setText("E ...?");
}
}

New Topic/Question
Reply



MultiQuote





|