C:\MortgageCalculator5.java:172: illegal start of expression
private class ClickListener implements ActionListener {
^
1 error
Tool completed with exit code 1
Here is my code so far:
// Java utilities
import javax.swing.*;
import java.awt.event.*;
import java.lang.Math.*;
import java.text.NumberFormat;
import javax.swing.ButtonGroup;
public class MortgageCalculator5 extends JFrame {
public static void main(String[] args) {
new MortgageCalculator5();
}
// Declare buttons, text fields, and labels
private JButton calculate;
private JButton exit;
private JButton calc;
private JTextField enterAmount;
private JTextField enterInterest;
private JTextField enterMonth;
private JLabel loan;
private JLabel interest;
private JLabel mRate;
private JLabel blankspace;
private JLabel data;
private JLabel data1;
private JLabel data2;
private JRadioButton term7;
private JRadioButton term15;
private JRadioButton term30;
public MortgageCalculator5() {
// set the size of the frame
this.setSize(350, 350);
// what the "exit" button will do when clicked.
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Title of frame
this.setTitle("Mortgage Calculator");
// Create the layout
JPanel mainpanel = new JPanel();
// panel1
JPanel panel1 = new JPanel();
data = new JLabel("Please fill out the amount of the loan.");
panel1.add(data);
mainpanel.add(panel1);
// panel2
JPanel panel2 = new JPanel();
loan = new JLabel("Amount of Loan");
enterAmount = new JTextField(8);
panel2.add(loan);
panel2.add(enterAmount);
mainpanel.add(panel2);
// panel3
JPanel panel3 = new JPanel();
data1 = new JLabel("Choose between rate & term");
panel3.add(data1);
mainpanel.add(panel3);
// panel4
JPanel panel4 = new JPanel();
ButtonGroup choice = new ButtonGroup();
term7 = new JRadioButton("7 Years @ 5.35%");
term15 = new JRadioButton("15 Years @ 5.5%");
term30 = new JRadioButton("30 Years @ 5.75%");
panel4.add(term7);
choice.add(term7);
panel4.add(term15);
choice.add(term15);
panel4.add(term30);
choice.add(term30);
mainpanel.add(panel4);
// panel5
JPanel panel5 = new JPanel();
calc = new JButton("Calculate Choice");
panel5.add(calc);
mainpanel.add(panel5);
// panel6
JPanel panel6 = new JPanel();
data2 = new JLabel("Or fill in yourself.");
panel6.add(data2);
mainpanel.add(panel6);
//panel7
JPanel panel7 = new JPanel();
interest = new JLabel("Interest Rate");
enterInterest = new JTextField(8);
panel7.add(interest);
panel7.add(enterInterest);
mainpanel.add(panel7);
// panel8
JPanel panel8 = new JPanel();
mRate = new JLabel("Term of Loan");
enterMonth = new JTextField(8);
panel8.add(mRate);
panel8.add(enterMonth);
mainpanel.add(panel8);
// panel9
JPanel panel9 = new JPanel();
blankspace = new JLabel(" ");
panel9.add(blankspace);
mainpanel.add(panel9);
// panel10
JPanel panel10 = new JPanel();
calculate = new JButton("Calculate");
exit = new JButton("Exit");
panel10.add(calculate);
panel10.add(exit);
mainpanel.add(panel10);
// Create Action Listeners
calculate.addActionListener(click);
exit.addActionListener(click);
calc.addActionListener(click);
// adds all 10 panels together
this.add(mainpanel);
// set see the frame
this.setVisible(true);
}
public void paint(Graphics g)
{
double width = 900.00;
int height= 400;
double x=1.0;
double y=0.0;
int counter = 0;
double xincrement = (width/(dblLoanDuration*12));
double yincrement = height/dblLoanAmount;
g.drawString("Payments", 65, 10);
while (counter <= 10) {
x = x + xincrement;
g.drawString(Integer.toString((int)((((dblLoanDuration*12)/10)*counter))), (int)((width/10)*counter)+55, 20);
counter++;
drawn = true;
}
double amount=dblLoanAmount;
double payment=amount/12;
g.drawString("Amount", 0, 20);
while (y < height) {
y = y + (height/12);
g.drawString(paymentFormat.format(amount), 0, (int)y);
amount = amount-payment;
}
// Creating the event listener
ClickListener click = new ClickListener();
// begin the events
private class ClickListener implements ActionListener {
public void actionPerformed(ActionEvent p) {
if (p.getSource() == calc) // if user clicks the calculate button
{
try {
// convert text entry into numbers
double receiveAmount = Double.parseDouble(enterAmount.getText());
// create the arrays for the three different loans
int Terms[] = {7, 15, 30}; // loan in years
double InterestArray[] = {5.35, 5.5, 5.75}; // interest as a percent
// Array 1
if (term7.isSelected()) {
double receiveInterest = InterestArray[0];
double receiveTerms = Terms[0];
double interest1 = (receiveInterest / (12 * 100));
double term1 = (receiveTerms * 12);
double term2 = (1 + interest1);
double pay1 = Math.pow(term2, -term1);
double payment = ((receiveAmount * interest1) / (1 - pay1));
double interestpay;
double remainBal = receiveAmount;
// create the number format
NumberFormat fixdecimal = NumberFormat.getNumberInstance();
fixdecimal.setMinimumFractionDigits(2);
fixdecimal.setMaximumFractionDigits(2);
// Create counter
for (int x = 1; x <= term1; x++) {
interestpay = (remainBal * interest1);
double interestout = 0;
remainBal = (remainBal - (payment - interestpay));
interestout = (interestout + interestpay);
// The output based on amount input and loan selection.
JOptionPane.showMessageDialog(null, "Original Balance = $" + receiveAmount +
"\nPayment #" + x + "\nMonthly Payment $" + fixdecimal.format(payment) +
"\nRemaining Balance $" + fixdecimal.format(remainBal) +
"\nInterest Paid $" + fixdecimal.format(interestpay),
"Payment History",
JOptionPane.PLAIN_MESSAGE);
}
// Exit or enter option.
int finalanswer = JOptionPane.showConfirmDialog(null, "Would you like to input a new amount?" +
"\n\n(chose Yes to continue or No to Exit)", "Continue", JOptionPane.YES_NO_OPTION);
if (finalanswer == JOptionPane.NO_OPTION) {
System.exit(0);
} else if (finalanswer == JOptionPane.YES_OPTION) {
// if the user chooses 'yes' the amount field will blank out
enterAmount.setText(null);
}
// Array 2
} else if (term15.isSelected()) {
double receiveInterest = InterestArray[1];
double receiveTerms = Terms[1];
double interest1 = (receiveInterest / (12 * 100));
double term1 = (receiveTerms * 12);
double term2 = (1 + interest1);
double pay1 = Math.pow(term2, -term1);
double payment = ((receiveAmount * interest1) / (1 - pay1));
double interestpay;
double remainBal = receiveAmount;
// create the number format
NumberFormat fixdecimal = NumberFormat.getNumberInstance();
fixdecimal.setMinimumFractionDigits(2);
fixdecimal.setMaximumFractionDigits(2);
// Create counter
for (int x = 1; x <= term1; x++) {
interestpay = (remainBal * interest1);
double interestout = 0;
remainBal = (remainBal - (payment - interestpay));
interestout = (interestout + interestpay);
// The output based on amount input and loan selection.
JOptionPane.showMessageDialog(null, "Original Balance = $" + receiveAmount +
"\nPayment #" + x + "\nMonthly Payment $" + fixdecimal.format(payment) +
"\nRemaining Balance $" + fixdecimal.format(remainBal) +
"\nInterest Paid $" + fixdecimal.format(interestpay),
"Payment History",
JOptionPane.PLAIN_MESSAGE);
}
// Exit or enter option.
int finalanswer = JOptionPane.showConfirmDialog(null, "Would you like to enter a new amount?" +
"\n\n(chose Yes to continue or No to Exit)", "Continue", JOptionPane.YES_NO_OPTION);
if (finalanswer == JOptionPane.NO_OPTION) {
System.exit(0);
// If the user chooses 'yes' the amount field will blank out
} else if (finalanswer == JOptionPane.YES_OPTION) {
enterAmount.setText(null);
}
// Array 3
} else if (term30.isSelected()) {
double receiveInterest = InterestArray[2];
double receiveTerms = Terms[2];
double interest1 = (receiveInterest / (12 * 100));
double term1 = (receiveTerms * 12);
double term2 = (1 + interest1);
double pay1 = Math.pow(term2, -term1);
double payment = ((receiveAmount * interest1) / (1 - pay1));
double interestpay;
double remainBal = receiveAmount;
// create the number format
NumberFormat fixdecimal = NumberFormat.getNumberInstance();
fixdecimal.setMinimumFractionDigits(2);
fixdecimal.setMaximumFractionDigits(2);
// Create counter
for (int x = 1; x <= term1; x++) {
interestpay = (remainBal * interest1);
double interestout = 0;
remainBal = (remainBal - (payment - interestpay));
interestout = (interestout + interestpay);
// The output based on amount input and loan selection.
JOptionPane.showMessageDialog(null, "Original Balance = $" + receiveAmount +
"\nPayment #" + x + "\nMonthly Payment $" + fixdecimal.format(payment) +
"\nRemaining Balance $" + fixdecimal.format(remainBal) +
"\nInterest Paid $" + fixdecimal.format(interestout),
"Payment History",
JOptionPane.PLAIN_MESSAGE);
}
// Exit or enter option.
int finalanswer = JOptionPane.showConfirmDialog(null, "Would you like to enter a new amount?" +
"\n\n(chose Yes to continue or No to Exit)", "Continue", JOptionPane.YES_NO_OPTION);
if (finalanswer == JOptionPane.NO_OPTION) {
System.exit(0);
// If the user chooses 'yes' the amount field will blank out
} else if (finalanswer == JOptionPane.YES_OPTION) {
enterAmount.setText(null);
}
}
}
catch (NumberFormatException e) {
}
}
// Create a new event
if (p.getSource() == calculate) {
try {
// turn text entries into numbers
double receiveAmount = Double.parseDouble(enterAmount.getText());
double receivePerc = Double.parseDouble(enterInterest.getText());
double receiveTerm = Double.parseDouble(enterMonth.getText());
double receiveInterest = receivePerc;
double receiveTerms = receiveTerm;
double interest1 = (receiveInterest / (12 * 100));
double term1 = (receiveTerms * 12);
double term2 = (1 + interest1);
double pay1 = Math.pow(term2, -term1);
double payment = ((receiveAmount * interest1) / (1 - pay1));
double interestpay;
double remainBal = receiveAmount;
// create the number format
NumberFormat fixdecimal = NumberFormat.getNumberInstance();
fixdecimal.setMinimumFractionDigits(2);
fixdecimal.setMaximumFractionDigits(2);
// Create counter
for (int x = 1; x <= term1; x++) {
interestpay = (remainBal * interest1);
double interestout = 0;
remainBal = (remainBal - (payment - interestpay));
interestout = (interestout + interestpay);
// The output based on amount input and loan selection.
JOptionPane.showMessageDialog(null, "Original Balance = $" + receiveAmount +
"\nPayment #" + x + "\nMonthly Payment $" + fixdecimal.format(payment) +
"\nRemaining Balance $" + fixdecimal.format(remainBal) +
"\nInterest Paid $" + fixdecimal.format(interestout),
"Payment History",
JOptionPane.PLAIN_MESSAGE);
}
// Exit or enter option.
int finalanswer = JOptionPane.showConfirmDialog(null, "Would you like to enter a new amount?" +
"\n\n(chose Yes to continue or No to Exit)", "Continue", JOptionPane.YES_NO_OPTION);
if (finalanswer == JOptionPane.NO_OPTION) {
System.exit(0);
// if the user chooses 'yes' the amount field will blank out
} else if (finalanswer == JOptionPane.YES_OPTION) {
// resets the entry fields
enterAmount.setText(null);
enterInterest.setText(null);
enterMonth.setText(null);
}
}
catch (NumberFormatException e) {
}
}
// Event Exit button
if (p.getSource() == exit) {
System.exit(0);
}
}
}
}
}
Thank You in Advance!!

New Topic/Question
Reply



MultiQuote






|