Write the program in Java (with a graphical user interface) so that it will allow the user to select which way they want to calculate a mortgage: by input of the amount of the mortgage, the term of the mortgage, and the interest rate of the mortgage payment or by input of the amount of a mortgage and then select from a menu of mortgage loans:
- 7 year at 5.35%
- 15 year at 5.5 %
- 30 year at 5.75%
In either case, display the mortgage payment amount and then, list the loan balance and interest paid for each payment over the term of the loan. Allow the user to loop back and enter a new amount and make a new selection, or quit. Insert comments in the program to document the program.
*/
import java.awt.GridLayout.*;
import java.awt.event.ActionEvent.*;
import java.awt.event.ActionListener.*;
import java.text.NumberFormat.*;
import java.io.*;
import java.text.DecimalFormat.*;
import java.swing.*;
import java.text.*;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
class Week4Mortgage extends JFrame implements ActionListener
{
//create applets
private JLabel AmountofMortgage;
private JLabel RateofMortgage;
private JTextField PaymentofMortgage;
private JLabel Interest;
private JLabel TermofMortgage;
private JTextField AmountEntered;
private JTextField InterestEntered;
private JTextField TermEntered;
private JButton Calculate;
private JButton Clear;
private JButton Exit;
//declare variables
double AmountofMortgage;
double PaymentofMortgage;
double Interest;
double TermofMortage;
double RateofMortgage;
public Week4Mortgage();
{
super ("Mortgage calculator");
setSize (400,200);
setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
setVisible (true);
Container calc = getContentPane();
calc.setBackground (Color.lightGray);
GridBagLayout gblm = new GridBagLayout();
GridLayout gridlayout= new GridLayout(5, 2, 20, 20);
//GridBagConstraints gbc = new GridBagConstraints();
calc.setLayout(gridlayout);
AmountofMortgage = new JLabel("Enter the Amount of Loan");
calc.add (AmountofMortgage,gridlayout);
AmountEntered = new JTextField ();
PaymentofMortgage = new JLabel("Enter the Payment of Loan");
calc.add (PaymentofMortgage,gridlayout);
AmountEntered = new JTextField();
Interest = JLabel("Enter the Interest of the Loan");
calc.add (Interest,gridlayout);
AmountEntered = new JTextField();
RateofMortgage = new JLabel("Enter the Rate of the Loan");
calc.add (RateofMortgage,gridlayout);
AmountEntered = new JTextField();
//Display action listeners
CalculateButton.addActionListener(this);
ClearButton.addActionListener(this);
ExitButton.addActionListener(this);
public static void main(String []args)
{
Week4Mortgage frame = new Week4Mortgage();
}
//method to calculate mortgage payment
public void actionPerformed(ActionEvent e)
{
boolean done = false;
Object command = e.getSource();
//display event for calculate button clicked
if(command = calculateButton)
{
try
{
double AmountofMortgage = Double.parseDouble(a.getText());
double TermofMortgage = Double.parseDouble(t.getText());
double RateofMortgage = Double.parseDouble(r.getText());
double Interest = (rate/100/12);
double PaymentofMortgage = (principal*interest)/(1-Math.pow(1/(1+interest), term*12));
String displayPayment = money.format(payment);
//Display decimal point format
DecimalFormat decimalPlaces=new DecimalFormat("0.00");
//does not allow 0 or null value
if(principal <=0 || rate <=0 || term<=0) throw new NumberFormatException();
else done = true;
}
// use this to catch exception
catch(NumberFormatException e)
{
JOptionPane.showMessageDialog("Your Monthtly Payment is ");
JOptionPane.showMessageDialog(null, "This calculation does not work, Please try something else!");
}
}
//display the code if user clicks the clear button
else if(command == clearButton)
{
p.setText(null);
r.setText(null);
displayPayment.setText(null);
paymentLabel.setText("Click the calculate button to display the payment amount");
}
//display the exit code
else if(command == exitButton)
{
System.exit(0);
}
}
}
}
Mortgage Payment Calculator
Page 1 of 1
Mortgage Payment Calculator Getting rid of these stupid errors
#1
Posted 11 May 2009 - 05:15 PM
HELP!!!!!!!!So for I've managed to go from 15 errors to 9 errors, what is it that I'm not seeing?
#3
Posted 12 May 2009 - 02:40 AM
Fuzzyness, on 11 May, 2009 - 11:16 PM, said:
Hmm.. I can tell you what i'm not seeing. . .
Your errors that compiler is giving you.
Your errors that compiler is giving you.
OOPS MY BAD.........HERE ARE THE ERRORS THAT THE COMPILER IS GIVING ME.
F:\Week4Mortgage.java:96: illegal start of expression
public static void main(String []args)
^
F:\Week4Mortgage.java:96: illegal start of expression
public static void main(String []args)
^
F:\Week4Mortgage.java:96: ';' expected
public static void main(String []args)
^
F:\Week4Mortgage.java:96: '.class' expected
public static void main(String []args)
^
F:\Week4Mortgage.java:96: ';' expected
public static void main(String []args)
^
F:\Week4Mortgage.java:102: illegal start of expression
public void actionPerformed(ActionEvent e)
^
F:\Week4Mortgage.java:102: illegal start of expression
public void actionPerformed(ActionEvent e)
^
F:\Week4Mortgage.java:102: ';' expected
public void actionPerformed(ActionEvent e)
^
F:\Week4Mortgage.java:102: ';' expected
public void actionPerformed(ActionEvent e)
^
9 errors
Tool completed with exit code 1
#5
Posted 12 May 2009 - 01:55 PM
Fuzzyness, on 12 May, 2009 - 01:09 PM, said:
public Week4Mortgage();
You need to remove that semicolon, and I dont think I saw a closing bracket for that method either
You need to remove that semicolon, and I dont think I saw a closing bracket for that method either
GOOD NOW I'M DOWN TO ONE ERROR.....
F:\Week4Mortgage.java:160: class, interface, or enum expected
}
^
1 error
Tool completed with exit code 1
#7
Posted 12 May 2009 - 03:54 PM
Fuzzyness, on 12 May, 2009 - 02:00 PM, said:
You add the closing bracket to the constructor of Week4Mortagage?
If you did and still shows, please print the line of code it appears at
If you did and still shows, please print the line of code it appears at
Oh ok, I might have put the bracket in the wrong place. I'll try it again and see what happens. Also when you say print the line of code it appears at do you mean by writing "System.out.println?"
Page 1 of 1

Start a new topic
Add Reply




MultiQuote
| 


