| | |
Mortgage Calculation
![]() |
•
•
Join Date: Sep 2004
Posts: 1
Reputation:
Solved Threads: 0
Hi, I am a novice in programming and need help in my mortgage calculation program. I have the GUI set up all functioning good the only problem I have is the calculation portion that is not doing its job.
Can anyone please guide me how to correct my problem?
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.text.DecimalFormat;
import java.util.*;
import java.lang.*;
import java.text.NumberFormat;
public class week1 extends JFrame implements ActionListener
{
//declaring fields for GUI
JTextField mortgageAmountField, interestRateField, yearsTermField, monthlyPayField;JButton monthButton;
JFrame frame;
int buttonCount = 0;
DecimalFormat fmt = new DecimalFormat("0.00");
//assigning labels to the fields
JLabel mortgageAmountLabel = new JLabel("Mortgage Amount:");
JLabel interestRateLabel = new JLabel("Interest Rate:");
JLabel yearsTermLabel=new JLabel("Term (Years):");
JLabel monthlyPayLabel=new JLabel();
public week1()
{
//declaring the title of the program
frame = new JFrame("Mortgage Calculator - Greta Setian");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//declaring panels 1 and 2
JPanel Panel1 = new JPanel();
JPanel Panel2 = new JPanel();
//assigning buttons to the panels
Panel1.add(mortgageAmountLabel);
mortgageAmountField = new JTextField(15);
Panel1.add(mortgageAmountField);
Panel1.add(interestRateLabel);
interestRateField = new JTextField(5);
Panel1.add(interestRateField);
Panel1.add(yearsTermLabel);
yearsTermField = new JTextField(5);
Panel1.add(yearsTermField);
Panel2.add(monthlyPayLabel);
monthlyPayField = new JTextField(5);
Panel2.add(monthlyPayField);
monthButton = new JButton("Reset");
monthButton.addActionListener(this);
Panel2.add(monthButton);
monthButton = new JButton("Exit");
monthButton.addActionListener(this);
Panel2.add(monthButton);
//setting up the quit button for the user to calculate the program
monthButton = new JButton("Calculate");
monthButton.addActionListener(this);
Panel2.add(monthButton);
//indicating the border layout of our frames
frame.getContentPane().add(Panel1, BorderLayout.NORTH);
frame.getContentPane().add(Panel2, BorderLayout.SOUTH);
frame.setSize(700, 100);
frame.setResizable(true);
frame.show();
}
//activating the action event so the user's input is taken
public void actionPerformed(ActionEvent event){
if(event.getSource() == monthButton)
}
public void MortgageCalcj1() {
double ortgageAmount=Double.parseDouble(mortgageAmountField.getText()); //O= Original amount of loan-hard coded
double interestRate=Double.parseDouble(interestRateField.getText()); //I=Interest rate-hard coded
double yearsTerm=Double.parseDouble(yearsTermField.getText()); //T=Term of loan- hard coded
double monthlyPay = (mortgageAmount*(interestRate / 12))/ (1 - (Math.pow(1 / (1 + (interestRate / 12)), yearsTerm)));
MortgageCalcj1 = new MortgageCalcj1(this);
//display the monthly payment
monthlyPayLabel.setText("Your Monthly Payment will be: " + fmt.format(monthlyPay));
//continue with button actionlistener
buttonCount++;
}
}
public static void main(String[] args)
{
week1 cal = new week1();
}
}
//end of programming
Can anyone please guide me how to correct my problem?
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.text.DecimalFormat;
import java.util.*;
import java.lang.*;
import java.text.NumberFormat;
public class week1 extends JFrame implements ActionListener
{
//declaring fields for GUI
JTextField mortgageAmountField, interestRateField, yearsTermField, monthlyPayField;JButton monthButton;
JFrame frame;
int buttonCount = 0;
DecimalFormat fmt = new DecimalFormat("0.00");
//assigning labels to the fields
JLabel mortgageAmountLabel = new JLabel("Mortgage Amount:");
JLabel interestRateLabel = new JLabel("Interest Rate:");
JLabel yearsTermLabel=new JLabel("Term (Years):");
JLabel monthlyPayLabel=new JLabel();
public week1()
{
//declaring the title of the program
frame = new JFrame("Mortgage Calculator - Greta Setian");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//declaring panels 1 and 2
JPanel Panel1 = new JPanel();
JPanel Panel2 = new JPanel();
//assigning buttons to the panels
Panel1.add(mortgageAmountLabel);
mortgageAmountField = new JTextField(15);
Panel1.add(mortgageAmountField);
Panel1.add(interestRateLabel);
interestRateField = new JTextField(5);
Panel1.add(interestRateField);
Panel1.add(yearsTermLabel);
yearsTermField = new JTextField(5);
Panel1.add(yearsTermField);
Panel2.add(monthlyPayLabel);
monthlyPayField = new JTextField(5);
Panel2.add(monthlyPayField);
monthButton = new JButton("Reset");
monthButton.addActionListener(this);
Panel2.add(monthButton);
monthButton = new JButton("Exit");
monthButton.addActionListener(this);
Panel2.add(monthButton);
//setting up the quit button for the user to calculate the program
monthButton = new JButton("Calculate");
monthButton.addActionListener(this);
Panel2.add(monthButton);
//indicating the border layout of our frames
frame.getContentPane().add(Panel1, BorderLayout.NORTH);
frame.getContentPane().add(Panel2, BorderLayout.SOUTH);
frame.setSize(700, 100);
frame.setResizable(true);
frame.show();
}
//activating the action event so the user's input is taken
public void actionPerformed(ActionEvent event){
if(event.getSource() == monthButton)
}
public void MortgageCalcj1() {
double ortgageAmount=Double.parseDouble(mortgageAmountField.getText()); //O= Original amount of loan-hard coded
double interestRate=Double.parseDouble(interestRateField.getText()); //I=Interest rate-hard coded
double yearsTerm=Double.parseDouble(yearsTermField.getText()); //T=Term of loan- hard coded
double monthlyPay = (mortgageAmount*(interestRate / 12))/ (1 - (Math.pow(1 / (1 + (interestRate / 12)), yearsTerm)));
MortgageCalcj1 = new MortgageCalcj1(this);
//display the monthly payment
monthlyPayLabel.setText("Your Monthly Payment will be: " + fmt.format(monthlyPay));
//continue with button actionlistener
buttonCount++;
}
}
public static void main(String[] args)
{
week1 cal = new week1();
}
}
//end of programming
![]() |
Similar Threads
- Starting wxPython (GUI code) (Python)
- Mortgage Calculator SR # 5 (Java)
- Problems with reading from a sequential file (C++)
- C++ sequential file / array (C++)
- Java equivalant to C's getchar() (Java)
- Mortgage Calculations (C++)
- program help (C++)
Other Threads in the Java Forum
- Previous Thread: How to insert an image into a GUI?
- Next Thread: wordcount
| Thread Tools | Search this Thread |
6 @param actuate android api applet application arc array arrays automation balls binary bluetooth bold business byte c++ chat class client code codesnippet collections compare component coordinates database defaultmethod detection doctype dragging ebook eclipse educational error file fractal froglogic game givemetehcodez graphics gui guitesting helpwithhomework hql html ide ideas image ingres input integer internet intersect invokingapacheantprogrammatically j2me java javaexcel javaprojects jni jpanel jtextarea julia linux list map method methods mobile mysql netbeans newbie nextline parameter php pong problem program programming project recursion recursive scanner sell server set sms sort sql string sun swing swt terminal threads tree web websites windows






