I am having multible problems with my code. Here is what it is supposed to do: 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. Here is the code.
/*Week 2 assignment
author: Chris Butler
Date: April 3, 2010
*/
import java.text.DecimalFormat;
import javax.swing.*;
import javax.swing.JTextField.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
public class PaymentCalculatorwk2 extends JFrame implements ActionListener
{
//Using Decimal format to display money
DecimalFormat money = new DecimalFormat ("$0,000.00");
//Panel for user input
JPanel firstRow = new JPanel();
JPanel secondRow = new JPanel();
JPanel thirdRow = new JPanel();
JPanel fourthRow = new JPanel();
//Panel for Buttons
JPanel fieldPanel = new JPanel();
JPanel buttonPanel = new JPanel();
//Labels with descriptions
JLabel loanLabel = new JLabel("Principle amount");
JTextField p = new JTextField(8);
JLabel YearLabel = JLabel("Year amount");
JTextField p = new JTextField(6);
JLabel rateLabel = new JLabel("Interest Rate");
JTextField p = new JTextField(6);
JLabel paymentLabel = new JLabel("Monthly Payment");
JLabel displaypayment = new JLabel(6);
//Create Buttons
JButton calculateButton = new JButton("Payment");
JButton exitButton = new JButton("Exit");
public static void main(String[] args)
{
PaymentCalculatorwk2 f = new PaymentCalculatorwk2();
f.setSize(450,350);
f.setTitle("Mortgage Calculator");
f.setLacation(300,350);
f.setVisible(true);
}
public PaymentCalculatorwk2()
{
Container c = getContentPane();
c.setLayout((new BorderLayout()));
fieldPanel.setLayout(new GridLayout(8,1));
FlowLayout rowSetup = new FlowLayout(FlowLayout.LEFT,5,3);
firstRow.setLayout(rowSetup);
secondRow.setLayout(rowSetup);
thirdRow.setLayout(rowSetup);
fourthRow.setLayout(rowSetup);
buttonPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
//add fields to rows
firstRow.add(loanLabel);
firstRow.add(p);
secondRow.add(termLabel);
secondRow.add(t);
thirdRow.add(rateLabel);
thirdRow.add(r);
fourthRow.add(paymentLabel);
fourthRow.add(displayPayment);
//Add rows to panel
fieldPanel.add(firstRow);
fieldPanel.add(secondRow);
fieldPanel.add(thirdRow);
fieldPanel.add(fourthRow);
//add button to panel
buttonPanel.add(calculateButton);
buttonPanel.add(quitButton);
//Add panels to frame
c.add(fieldPanel, BorderLayout.CENTER);
c.add(buttonPanel, BorderLayout.SOUTH);
//add fuctionality to the button
calculateButton.addActionListener(this);
quitButton.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
//Calculations for user input
PaymentCalculator();
}
public void PaymentCalculator()
{
//Calculate monthly payment of loan
double principle = 0; // Principle Loan Amount
double AnnualInterest = 0; // Annual Interest Amaount
int Months = 0; // Number of Months
double MonthlyInterest= AnnualInterest/(12*100); // Monthly interest
double MonthlyPayment = 0; // Monthly Payment
double CurrentMonthlyInterest = 0; // Current Monthly Interest
double PaidPerMonth = 0; // Amount paid per month
double NewBalance = 0; // monthly Balance
MonthlyPayment = principle * (MonthlyInterest / (1 - (Math.pow(1 + MonthlyInterest, -Months))));
String displayMonthlyPayment = Decimal.format (Payment);
System.out.println(payment);
}
}
Here is the errors.
F:\School\PRG421\week 1\PaymentCalculatorwk2.java:35: p is already defined in PaymentCalculatorwk2
JTextField p = new JTextField(6);
^
F:\School\PRG421\week 1\PaymentCalculatorwk2.java:37: p is already defined in PaymentCalculatorwk2
JTextField p = new JTextField(6);
^
F:\School\PRG421\week 1\PaymentCalculatorwk2.java:34: cannot find symbol
symbol : method JLabel(java.lang.String)
location: class PaymentCalculatorwk2
JLabel YearLabel = JLabel("Year amount");
^
F:\School\PRG421\week 1\PaymentCalculatorwk2.java:39: cannot find symbol
symbol : constructor JLabel(int)
location: class javax.swing.JLabel
JLabel displaypayment = new JLabel(6);
^
F:\School\PRG421\week 1\PaymentCalculatorwk2.java:55: cannot find symbol
symbol : method setLacation(int,int)
location: class PaymentCalculatorwk2
f.setLacation(300,350);
^
F:\School\PRG421\week 1\PaymentCalculatorwk2.java:75: cannot find symbol
symbol : variable termLabel
location: class PaymentCalculatorwk2
secondRow.add(termLabel);
^
F:\School\PRG421\week 1\PaymentCalculatorwk2.java:76: cannot find symbol
symbol : variable t
location: class PaymentCalculatorwk2
secondRow.add(t);
^
F:\School\PRG421\week 1\PaymentCalculatorwk2.java:78: cannot find symbol
symbol : variable r
location: class PaymentCalculatorwk2
thirdRow.add(r);
^
F:\School\PRG421\week 1\PaymentCalculatorwk2.java:80: cannot find symbol
symbol : variable displayPayment
location: class PaymentCalculatorwk2
fourthRow.add(displayPayment);
^
F:\School\PRG421\week 1\PaymentCalculatorwk2.java:90: cannot find symbol
symbol : variable quitButton
location: class PaymentCalculatorwk2
buttonPanel.add(quitButton);
^
F:\School\PRG421\week 1\PaymentCalculatorwk2.java:98: cannot find symbol
symbol : variable quitButton
location: class PaymentCalculatorwk2
quitButton.addActionListener(this);
^
F:\School\PRG421\week 1\PaymentCalculatorwk2.java:119: cannot find symbol
symbol : variable Payment
location: class PaymentCalculatorwk2
String displayMonthlyPayment = Decimal.format (Payment);
^
F:\School\PRG421\week 1\PaymentCalculatorwk2.java:119: cannot find symbol
symbol : variable Decimal
location: class PaymentCalculatorwk2
String displayMonthlyPayment = Decimal.format (Payment);
^
F:\School\PRG421\week 1\PaymentCalculatorwk2.java:120: cannot find symbol
symbol : variable payment
location: class PaymentCalculatorwk2
System.out.println(payment);
^
14 errors
Tool completed with exit code 1
Please help.