Mortgage Calculator with Graph

Have error and do not seem to get it fixed! Plz..Help

  • (2 Pages)
  • +
  • 1
  • 2

23 Replies - 11624 Views - Last Post: 04 May 2010 - 08:00 PM Rate Topic: -----

#1 cpeachy1223  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 97
  • Joined: 23-September 07

Mortgage Calculator with Graph

Posted 09 November 2008 - 08:15 PM

I am trying to get this program to run but keep getting a compile error.

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!!

Is This A Good Question/Topic? 0
  • +

Replies To: Mortgage Calculator with Graph

#2 stauffski  Icon User is offline

  • D.I.C Head

Reputation: 27
  • View blog
  • Posts: 210
  • Joined: 03-November 07

Re: Mortgage Calculator with Graph

Posted 09 November 2008 - 08:49 PM

Fixed two things but there are still more that you will have to fix.

I fixed: a misplaced brace, and imported java.awt.Graphics
Next up: create the variable click

// Java utilities

import javax.swing.*;
import java.awt.event.*;
import java.lang.Math.*;
import java.text.NumberFormat;
import javax.swing.ButtonGroup;
import java.awt.Graphics;

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);
            }
        }
    }
}



Good Luck!
Was This Post Helpful? 0
  • +
  • -

#3 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4333
  • View blog
  • Posts: 12,128
  • Joined: 18-April 07

Re: Mortgage Calculator with Graph

Posted 09 November 2008 - 08:50 PM

Ok you have a few problems here. The first is that you don't have a closing curly brace before the line 172 which closes off the paint method. Instead you have an extra closing brace all the way at the end of the program that should not be there.

My guess is that you are trying to write in an inner class but it can't be defined inside another function. So make sure you close off the paint method and get rid of the extra one on the end.

Second problem is that in your paint() method you have the variables dblLoanDuration, dblLoanAmount, drawn, and paymentFormat variables which have not been defined. You didn't happen to copy this code from somewhere did you and forgot to carry along the variables definition?

Next you use the Graphics object in your paint. The graphics object is in the java.awt package, so import that at the top.

After that you declared your ClickListener as a variable click. Problem is, you defined this after you attempt to add it to your controls. So move it up before the section...

// Create Action Listeners
        calculate.addActionListener(click);



That way click will be defined before you put it in the control addActionListeners.

Once you fix all these errors, then you will get the program compiling and then you can continue with testing and tweaking.

Good luck to you.

"At DIC we be mortgage calculating and fixing code ninjas... we also fix bicycles, flat tires, dim light bulbs and your worst enemy if you pay enough." :snap:
Was This Post Helpful? 0
  • +
  • -

#4 cpeachy1223  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 97
  • Joined: 23-September 07

Re: Mortgage Calculator with Graph

Posted 09 November 2008 - 08:58 PM

View PostMartyr2, on 9 Nov, 2008 - 07:50 PM, said:

Ok you have a few problems here. The first is that you don't have a closing curly brace before the line 172 which closes off the paint method. Instead you have an extra closing brace all the way at the end of the program that should not be there.

My guess is that you are trying to write in an inner class but it can't be defined inside another function. So make sure you close off the paint method and get rid of the extra one on the end.

Second problem is that in your paint() method you have the variables dblLoanDuration, dblLoanAmount, drawn, and paymentFormat variables which have not been defined. You didn't happen to copy this code from somewhere did you and forgot to carry along the variables definition?

Next you use the Graphics object in your paint. The graphics object is in the java.awt package, so import that at the top.

After that you declared your ClickListener as a variable click. Problem is, you defined this after you attempt to add it to your controls. So move it up before the section...

// Create Action Listeners
        calculate.addActionListener(click);





That way click will be defined before you put it in the control addActionListeners.

Once you fix all these errors, then you will get the program compiling and then you can continue with testing and tweaking.

Good luck to you.

"At DIC we be mortgage calculating and fixing code ninjas... we also fix bicycles, flat tires, dim light bulbs and your worst enemy if you pay enough." :snap:

Thank you for the help....as for the Create Action Listeners I did have it up but was moving it around trying to get things to work. I wont lie to you as for the Paint method this was what the teacher had put into the class forum and yes forgot to change the variables.

Paint is the way to go.

Here is some help from Sun:

http://java.sun.com/.../awt/Paint.html


And since I want to make sure that everyone gets the last part of this assignment, I am going to give you all a huge gift:

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;
}

William Davis
University of Phoenix Online Faculty

As for the other things I thank you and will get to work on fixing it! Will keep you updated! Thanks again.
Was This Post Helpful? 0
  • +
  • -

#5 cpeachy1223  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 97
  • Joined: 23-September 07

Re: Mortgage Calculator with Graph

Posted 09 November 2008 - 09:30 PM

View Postcpeachy1223, on 9 Nov, 2008 - 07:58 PM, said:

View PostMartyr2, on 9 Nov, 2008 - 07:50 PM, said:

Ok you have a few problems here. The first is that you don't have a closing curly brace before the line 172 which closes off the paint method. Instead you have an extra closing brace all the way at the end of the program that should not be there.

My guess is that you are trying to write in an inner class but it can't be defined inside another function. So make sure you close off the paint method and get rid of the extra one on the end.

Second problem is that in your paint() method you have the variables dblLoanDuration, dblLoanAmount, drawn, and paymentFormat variables which have not been defined. You didn't happen to copy this code from somewhere did you and forgot to carry along the variables definition?

Next you use the Graphics object in your paint. The graphics object is in the java.awt package, so import that at the top.

After that you declared your ClickListener as a variable click. Problem is, you defined this after you attempt to add it to your controls. So move it up before the section...

// Create Action Listeners
        calculate.addActionListener(click);


I dont get it Martyr I took out one of the closing curly brace at the very end and moved the clicklistener back up and now I get the same two errors that caused me to move them in the first place.




That way click will be defined before you put it in the control addActionListeners.

Once you fix all these errors, then you will get the program compiling and then you can continue with testing and tweaking.

Good luck to you.

"At DIC we be mortgage calculating and fixing code ninjas... we also fix bicycles, flat tires, dim light bulbs and your worst enemy if you pay enough." :snap:

Thank you for the help....as for the Create Action Listeners I did have it up but was moving it around trying to get things to work. I wont lie to you as for the Paint method this was what the teacher had put into the class forum and yes forgot to change the variables.

Paint is the way to go.

Here is some help from Sun:

http://java.sun.com/.../awt/Paint.html


And since I want to make sure that everyone gets the last part of this assignment, I am going to give you all a huge gift:

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;
}

William Davis
University of Phoenix Online Faculty

As for the other things I thank you and will get to work on fixing it! Will keep you updated! Thanks again.



View Postcpeachy1223, on 9 Nov, 2008 - 08:28 PM, said:

View Postcpeachy1223, on 9 Nov, 2008 - 07:58 PM, said:

View PostMartyr2, on 9 Nov, 2008 - 07:50 PM, said:

Ok you have a few problems here. The first is that you don't have a closing curly brace before the line 172 which closes off the paint method. Instead you have an extra closing brace all the way at the end of the program that should not be there.

My guess is that you are trying to write in an inner class but it can't be defined inside another function. So make sure you close off the paint method and get rid of the extra one on the end.

Second problem is that in your paint() method you have the variables dblLoanDuration, dblLoanAmount, drawn, and paymentFormat variables which have not been defined. You didn't happen to copy this code from somewhere did you and forgot to carry along the variables definition?

Next you use the Graphics object in your paint. The graphics object is in the java.awt package, so import that at the top.

After that you declared your ClickListener as a variable click. Problem is, you defined this after you attempt to add it to your controls. So move it up before the section...

// Create Action Listeners
        calculate.addActionListener(click);


I dont get it Martyr I took out one of the closing curly brace at the very end and moved the clicklistener back up and now I get the same two errors that caused me to move them in the first place.




That way click will be defined before you put it in the control addActionListeners.

Once you fix all these errors, then you will get the program compiling and then you can continue with testing and tweaking.

Good luck to you.

"At DIC we be mortgage calculating and fixing code ninjas... we also fix bicycles, flat tires, dim light bulbs and your worst enemy if you pay enough." :snap:

Thank you for the help....as for the Create Action Listeners I did have it up but was moving it around trying to get things to work. I wont lie to you as for the Paint method this was what the teacher had put into the class forum and yes forgot to change the variables.

Paint is the way to go.

Here is some help from Sun:

http://java.sun.com/.../awt/Paint.html


And since I want to make sure that everyone gets the last part of this assignment, I am going to give you all a huge gift:

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;
}

William Davis
University of Phoenix Online Faculty

As for the other things I thank you and will get to work on fixing it! Will keep you updated! Thanks again.


I dont get it Martyr I took out one of the closing curly brace at the very end and moved the clicklistener back up and now I get the same two errors that caused me to move them in the first place.

C:\MortgageCalculator5.java:176: illegal start of expression
private class ClickListener implements ActionListener {
^
C:\MortgageCalculator5.java:394: reached end of file while parsing
}
^
2 errors

Tool completed with exit code 1

This post has been edited by cpeachy1223: 09 November 2008 - 09:32 PM

Was This Post Helpful? 0
  • +
  • -

#6 cpeachy1223  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 97
  • Joined: 23-September 07

Re: Mortgage Calculator with Graph

Posted 09 November 2008 - 10:29 PM

This is an updated of my code and there are somethings I have not changed yet....as in some variables. But I changed where my ClickListener was and got rid of one of the curly braces at the very end of program, But now I have two errors that I had earlier and that was the reason I changed things around in first place.

The errors are as follows:

C:\MortgageCalculator5.java:176: illegal start of expression
private class ClickListener implements ActionListener {
^
C:\MortgageCalculator5.java:394: reached end of file while parsing
}
^
2 errors

Tool completed with exit code 1

Here is my changed code and I do know that I still have to define some variables left in my paint method.
/* Assignment 5 for Week 5
 * Date:November 10, 2008
 * Author: Carolyn Peach
 * Filename:MortgageCalculator5
 * This program will create a GUI that will allow users to select which way they want to calculate a mortgage and viewing a graph.
 * This program is a modified from early programs for service change request #7 of SR-mf-003.
 */

// Java utilities

import javax.swing.*;
import java.awt.event.*;
import java.lang.Math.*;
import java.text.NumberFormat;
import javax.swing.ButtonGroup;
import java.awt.Graphics;

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);

		// Creating the event listener
		ClickListener click = new ClickListener();

		// 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 dblLoanDuration;
			double LoanAmount;

			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;
		}

	// 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);
			}
		}
	}
}


Was This Post Helpful? 0
  • +
  • -

#7 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4333
  • View blog
  • Posts: 12,128
  • Joined: 18-April 07

Re: Mortgage Calculator with Graph

Posted 09 November 2008 - 10:36 PM

Did you add the closing brace back in before the actual class on line 147? You add one to close off the paint and then you delete one at the end. You don't just delete the one on the end and that is it.

:)
Was This Post Helpful? 0
  • +
  • -

#8 cpeachy1223  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 97
  • Joined: 23-September 07

Re: Mortgage Calculator with Graph

Posted 09 November 2008 - 10:42 PM

View PostMartyr2, on 9 Nov, 2008 - 09:36 PM, said:

Did you add the closing brace back in before the actual class on line 147? You add one to close off the paint and then you delete one at the end. You don't just delete the one on the end and that is it.

:)


I did add one before line 147 and I took out the last one at the end. Unless I am missing one....But I dont see it. Also I have been reading over chapter in school book and I can not find what I am to set drawn variable too. He gave us the give me so to speak but all I see is where it is " drawn = true"! True to what? I am so frickin lost! :crazy:
Was This Post Helpful? 0
  • +
  • -

#9 cpeachy1223  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 97
  • Joined: 23-September 07

Re: Mortgage Calculator with Graph

Posted 10 November 2008 - 07:00 PM

View Postcpeachy1223, on 9 Nov, 2008 - 09:42 PM, said:

View PostMartyr2, on 9 Nov, 2008 - 09:36 PM, said:

Did you add the closing brace back in before the actual class on line 147? You add one to close off the paint and then you delete one at the end. You don't just delete the one on the end and that is it.

:)


I did add one before line 147 and I took out the last one at the end. Unless I am missing one....But I dont see it. Also I have been reading over chapter in school book and I can not find what I am to set drawn variable too. He gave us the give me so to speak but all I see is where it is " drawn = true"! True to what? I am so frickin lost! :crazy:


Hello guys,

I still have not been able to resolve this error in program.
C:\Assignment Programs Made Java 2\MortgageCalculator5.java:177: illegal start of expression
private class ClickListener implements ActionListener
^
1 error

Tool completed with exit code 1

Also I am trying to set my variables for the give me the teacher gave us on the paint method....but I do not understand drawn = true. If I am to set a variable to drawn....what would that be.....true to what? I am still lost!! :blink:
Update on code:
/* Assignment 5 for Week 5
 * Date:November 10, 2008
 * Author: Carolyn Peach
 * Filename:MortgageCalculator5
 * This program will create a GUI that will allow users to select which way they want to calculate a mortgage and viewing a graph.
 * This program is a modified from early programs for service change request #7 of SR-mf-003.
 */

// Java utilities

import javax.swing.*;
import java.awt.event.*;
import java.lang.Math.*;
import java.text.NumberFormat;
import javax.swing.ButtonGroup;
import java.awt.Graphics;

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);

		// adds all 10 panels together
		this.add(mainpanel);

		// set see the frame
		this.setVisible(true);

		 // Create Action Listeners
		 calculate.addActionListener(click);
		 exit.addActionListener(click);
		 calc.addActionListener(click);

		 // Creating the event listener
		 ClickListener click = new ClickListener();

	}

	public void paint(Graphics g)
		{
			double dblLoanDuration;
			double LoanAmount;

			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;
		}

	// 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);
			}
		}
	}
}
	}

Can someone please help me....I can not see if there is anything else I need to fix if I can not get past this compile error! I know there is more things wrong with it!
Was This Post Helpful? 0
  • +
  • -

#10 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8332
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Mortgage Calculator with Graph

Posted 10 November 2008 - 07:25 PM

I guess that

	// Create Action Listeners
	calculate.addActionListener(click);
	exit.addActionListener(click);
	calc.addActionListener(click);

	// Creating the event listener
	ClickListener click = new ClickListener();



should be replaced by

	// Creating the event listener
	ClickListener click = new ClickListener();

	// Create Action Listeners
	calculate.addActionListener(click);
	exit.addActionListener(click);
	calc.addActionListener(click);



but to see the ClickListener class you'll have to indent it to the left

from
	while (y < height) {
		y = y + (height/12);
		g.drawString(paymentFormat.format(amount), 0, (int)y);
		amount = amount-payment;
	}

	// begin the events
	private class ClickListener implements ActionListener



to

	while (y < height) {
		y = y + (height/12);
		g.drawString(paymentFormat.format(amount), 0, (int)y);
		amount = amount-payment;
	}
}
// begin the events
private class ClickListener implements ActionListener
{



Which means that you have to remove the last last last } in your file

Then you still have to define the undefined variables:
- dblLoanAmount
- drawn
- paymentFormat
Was This Post Helpful? 0
  • +
  • -

#11 cpeachy1223  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 97
  • Joined: 23-September 07

Re: Mortgage Calculator with Graph

Posted 10 November 2008 - 07:32 PM

Ok thanks pbl I will work on those and see what happens. But the question on my mind is "drawn = true;".....true to what I have been going over text book and googling it but I can not seem to see how or what I am to set it to. Like I told Martyr the paint method was a give me to all of the students in class by teacher. The paint method he wrote and he said we had to define the variables. OK that is fine with me but I do not understand drawn = true? I hope this makes sense to you.
Was This Post Helpful? 0
  • +
  • -

#12 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8332
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Mortgage Calculator with Graph

Posted 10 November 2008 - 07:38 PM

View Postcpeachy1223, on 10 Nov, 2008 - 06:32 PM, said:

Ok thanks pbl I will work on those and see what happens. But the question on my mind is "drawn = true;".....true to what I have been going over text book and googling it but I can not seem to see how or what I am to set it to. Like I told Martyr the paint method was a give me to all of the students in class by teacher. The paint method he wrote and he said we had to define the variables. OK that is fine with me but I do not understand drawn = true? I hope this makes sense to you.

Sorry didn't go that deep understanding your code...
just managed to find out the "class not found" error due to the fact that a } was missing and that you start a private class in the middle of a method
Was This Post Helpful? 0
  • +
  • -

#13 cpeachy1223  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 97
  • Joined: 23-September 07

Re: Mortgage Calculator with Graph

Posted 10 November 2008 - 07:38 PM

Sweet...pbl that did the trick on the compile error. Now I am only getting the compile errors because those variables are not defined! :D

Now if someone can just answer the post I added right before this one and explain to me about drawn = true I would be forever thankful! Be back in a few minutes working on other variables except the drawn one....because I do not understand that one yet.
Was This Post Helpful? 0
  • +
  • -

#14 cpeachy1223  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 97
  • Joined: 23-September 07

Re: Mortgage Calculator with Graph

Posted 10 November 2008 - 08:54 PM

Ok I added my variables and now I am getting a couple of different errors. I listed my variables but the errors say it may not have been initialized!

C:\Assignment Programs Made Java 2\MortgageCalculator5.java:160: variable dblLoanDuration might not have been initialized
double xincrement = (width/(dblLoanDuration*12));
^
C:\Assignment Programs Made Java 2\MortgageCalculator5.java:161: variable dblLoanAmount might not have been initialized
double yincrement = height/dblLoanAmount;
^
2 errors

Tool completed with exit code 1

Here is my updated code:
/* Assignment 5 for Week 5
 * Date:November 10, 2008
 * Author: Carolyn Peach
 * Filename:MortgageCalculator5
 * This program will create a GUI that will allow users to select which way they want to calculate a mortgage and viewing a graph.
 * This program is a modified from early programs for service change request #7 of SR-mf-003.
 */

// Java utilities

import javax.swing.*;
import java.awt.event.*;
import java.lang.Math.*;
import java.text.NumberFormat;
import javax.swing.ButtonGroup;
import java.awt.Graphics;
import java.text.DecimalFormat;


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);

		// adds all 10 panels together
		this.add(mainpanel);

		// set see the frame
		this.setVisible(true);

		// Creating the event listener
		ClickListener click = new ClickListener();

			 // Create Action Listeners
			 calculate.addActionListener(click);
			 exit.addActionListener(click);
			 calc.addActionListener(click);
	}

	public void paint(Graphics g)
		{

			DecimalFormat paymentFormat = new DecimalFormat ("$0.00");

			int dblLoanDuration;
			int dblLoanAmount;
			boolean drawn;
			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;
		}
}
	// 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);
			}
		}
	}
}



Any ideas??
Was This Post Helpful? 0
  • +
  • -

#15 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8332
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Mortgage Calculator with Graph

Posted 10 November 2008 - 09:13 PM

View Postcpeachy1223, on 10 Nov, 2008 - 06:38 PM, said:

Sweet...pbl that did the trick on the compile error. Now I am only getting the compile errors because those variables are not defined! :D


"Sweet...pbl" ... I hope you are a she :D

		   int dblLoanDuration;
		   double xincrement = (width/(dblLoanDuration*12));



Java complains about the fact that db;:oanDuration might not have been initialized
And the Java compiler is right... you were abou to divide by 0
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2