Java Payment Calculator

  • (2 Pages)
  • +
  • 1
  • 2

15 Replies - 894 Views - Last Post: 11 July 2011 - 03:03 PM Rate Topic: -----

#1 javaconfused  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 11-July 11

Java Payment Calculator

Posted 11 July 2011 - 11:16 AM

I am attempting to get my GUI to work. It compiles correctly but will not run.I do not want my homework done for me as I have it finished, just have something missing that is messing it all up. A quick... THIS IS YOUR PROBLEM will help a lot. AND.. I get the DOS screen pop up with executed, it reads "Exception in thread "main" java.lang.NoSuchMethodError: main"

Here is my code.

import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.NumberFormat;
import java.util.Date;

import javax.swing.*;

public class MortgageCalculatorGUI extends JFrame
{
    // declare GUI element viariables

    // labels
    private JLabel lblAmount = new JLabel("Loan Amount: ");
    private JLabel lblTerm = new JLabel("Term (Year): ");
    private JLabel lblInterest = new JLabel("Interest Rate: %");

    // text field
    private JTextField txtAmount = new JTextField(10);
    private JTextField txtTerm = new JTextField(10);
    private JTextField txtInterest = new JTextField(10);

    // button
    private JButton btnCalc = new JButton("Calculate");
    private JButton btnReset = new JButton("Reset");

    // text area
    private JTextArea areaResult = new JTextArea(30, 10);

    // number format
    private NumberFormat fmt = NumberFormat.getCurrencyInstance();

    // constructor
    public MortgageCalculatorGUI()
    {
        super("Mortgage Calculator - PRG 421 Week 2");

        // initialize the GUI

        // set layout to borderlayout
        super.setLayout(new BorderLayout());

        // create a new panel with grid layout, 4 rows 2 columns
        JPanel pnInput = new JPanel(new GridLayout(4, 2));

        // add labels and text fields to panel
        pnInput.add(lblAmount);
        pnInput.add(txtAmount);
        pnInput.add(lblTerm);
        pnInput.add(txtTerm);
        pnInput.add(lblInterest);
        pnInput.add(txtInterest);
        pnInput.add(btnCalc);
        pnInput.add(btnReset);

        // add action listener to buttons
        btnCalc.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                buttonCalc();
            }
        });
        btnReset.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                buttonreset();
            }
        });

        // add panel to north
        add(pnInput, BorderLayout.NORTH);

        // add result area to center
        add(new JScrollPane(areaResult), BorderLayout.CENTER);

        // set property
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setSize(400, 300);

    } // end contructor

    // reset the text, invoked when button reset is clicked
    protected void buttonreset()
    {
        txtAmount.setText("");
        txtTerm.setText("");
        txtInterest.setText("");
        areaResult.setText("");
    } // end buttonreset

    // calculate the monthly payment and display the result, invoked when button "Calculate" is clicked
    protected void buttonCalc()
    {
        double principal = -1;
        double interestYearly = -1;
        int termYears = -1;

        // get amount, term, interest from the text field
        try
        {
            principal = Double.parseDouble(txtAmount.getText());
            if (principal <= 0)
                throw new Exception();
            termYears = Integer.parseInt(txtTerm.getText());
            if (termYears <= 0)
                throw new Exception();
            interestYearly = Double.parseDouble(txtInterest.getText());
            if (interestYearly <= 0 || interestYearly >= 100)
                throw new Exception();
        }
        catch (Exception e)
        {
            if (principal <= 0)
                JOptionPane.showMessageDialog(this, "Please enter positive amount.");
            else if (termYears <= 0)
                JOptionPane.showMessageDialog(this, "Please enter positive years.");
            else if (interestYearly <= 0 || interestYearly >= 100)
                JOptionPane.showMessageDialog(this, "Please enter valid interest rate.");
            return;
        }

     }
		    /**
				     * Method to calculate monthly payment
				     * @param principal
				     * @param interestYearly
				     * @param termYears
				     * @return monthly payment
             */
		    public double calcMonthlyPayment(double principal, double interestYearly, int termYears)
		    {
		        // calculate monthly interest rate
		        double interestMonthly = interestYearly / 12.0;
		        // calculate the number of payments
		        double numberOfPayments = termYears * 12;

		        //  calculate the monthly payment and return the value
		        return (principal * interestMonthly) / (1.0 - (Math.pow((1.0 + interestMonthly), -numberOfPayments)));
		   }
			 }



Is This A Good Question/Topic? 0
  • +

Replies To: Java Payment Calculator

#2 smohd  Icon User is offline

  • Critical Section
  • member icon


Reputation: 1752
  • View blog
  • Posts: 4,409
  • Joined: 14-March 10

Re: Java Payment Calculator

Posted 11 July 2011 - 11:28 AM

You need main method to run your application. This is where your application will start to work(since it is not applet ). What you have to do is to have a main method and instantiate your frame and make it visible(by setting its visible property to true). You may either create another class and put a main in it(where by this class should be the main class) or put your main() method in the same class :)

This post has been edited by smohd: 11 July 2011 - 11:34 AM

Was This Post Helpful? 2
  • +
  • -

#3 javaconfused  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 11-July 11

Re: Java Payment Calculator

Posted 11 July 2011 - 11:37 AM

Without sounding like I have no clue... would you mind giving me an example of where to put the main()? I tried to put it in the same class to no avail. Getting more errors. I do appreciate your time. Thank you
Was This Post Helpful? 0
  • +
  • -

#4 smohd  Icon User is offline

  • Critical Section
  • member icon


Reputation: 1752
  • View blog
  • Posts: 4,409
  • Joined: 14-March 10

Re: Java Payment Calculator

Posted 11 July 2011 - 11:46 AM

How did you put it? can you show your updated code with the main and tell those errors that happen? Dont afraid of errors, it may be those errors are somewhere in your application and need to be solved, but if you have no main() are not displayed because the program is not starting...
The main is like normal one used in everyday life:
public class MortgageCalculatorGUI extends JFrame{
//I skip your codes
  public static void main(String[] args){
   // Instantiate your MortgageCalculatorGUI class here
   // and if there are methods which must be called to do your work
   // call them here using your object....
  }
} 

Was This Post Helpful? 1
  • +
  • -

#5 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10175
  • View blog
  • Posts: 37,582
  • Joined: 27-December 08

Re: Java Payment Calculator

Posted 11 July 2011 - 11:50 AM

It goes in your class, but not in any other method. :)
class MortgageCalculatorGUI extends JFrame{
    //all your other code

    public static void main(String[] args){
         MortgageCalculatorGUI frame = new MortgageCalculatorGUI();
    }
}


Was This Post Helpful? 1
  • +
  • -

#6 javaconfused  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 11-July 11

Re: Java Payment Calculator

Posted 11 July 2011 - 11:57 AM

Thank you, that set my errors on fire! LOL
Another question, do I need to call each of those lines with "private"? Those are the errors I'm getting now, the ones I have the "private" on.
Was This Post Helpful? 0
  • +
  • -

#7 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10175
  • View blog
  • Posts: 37,582
  • Joined: 27-December 08

Re: Java Payment Calculator

Posted 11 July 2011 - 11:58 AM

Post your code and errors.
Was This Post Helpful? 0
  • +
  • -

#8 javaconfused  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 11-July 11

Re: Java Payment Calculator

Posted 11 July 2011 - 12:11 PM

I took the above answer off and went to this one because it was not initializing the action event.. So this is the error I'm getting for the following code. I will then implement the main() where required. For the moment though, I'm getting a lot of errors on placing that particular command (main()) at the end... where suggested.

MortgageCalculatorGUI in not abstract and does not override abstract method actionperformed (java.awt.event.ActionEvent) in java.awt.event.ActionListener public class MortgageCalculatorGUI exstends JFrame implements ActionListener ^

1 error

import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.NumberFormat;
import java.util.Date;

import javax.swing.*;

public class MortgageCalculatorGUI extends JFrame implements ActionListener
{

    // declare GUI element viariables

    // labels
    private JLabel lblAmount = new JLabel("Loan Amount: ");
    private JLabel lblTerm = new JLabel("Term (Year): ");
    private JLabel lblInterest = new JLabel("Interest Rate: %");

    // text field
    private JTextField txtAmount = new JTextField(10);
    private JTextField txtTerm = new JTextField(10);
    private JTextField txtInterest = new JTextField(10);

    // button
    private JButton btnCalc = new JButton("Calculate");
    private JButton btnReset = new JButton("Reset");

    // text area
    private JTextArea areaResult = new JTextArea(30, 10);

    // number format
    private NumberFormat fmt = NumberFormat.getCurrencyInstance();

    // constructor
    public MortgageCalculatorGUI()
    {
        super("Mortgage Calculator - PRG 421 Week 2");

        // initialize the GUI

        // set layout to borderlayout
        super.setLayout(new BorderLayout());

        // create a new panel with grid layout, 4 rows 2 columns
        JPanel pnInput = new JPanel(new GridLayout(4, 2));

        // add labels and text fields to panel
        pnInput.add(lblAmount);
        pnInput.add(txtAmount);
        pnInput.add(lblTerm);
        pnInput.add(txtTerm);
        pnInput.add(lblInterest);
        pnInput.add(txtInterest);
        pnInput.add(btnCalc);
        pnInput.add(btnReset);

        // add action listener to buttons
        btnCalc.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                buttonCalc();
            }
        });
        btnReset.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                buttonreset();
            }
        });

        // add panel to north
        add(pnInput, BorderLayout.NORTH);

        // add result area to center
        add(new JScrollPane(areaResult), BorderLayout.CENTER);

        // set property
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setSize(400, 300);

    } // end contructor

    // reset the text, invoked when button reset is clicked
    protected void buttonreset()
    {
        txtAmount.setText("");
        txtTerm.setText("");
        txtInterest.setText("");
        areaResult.setText("");
    } // end buttonreset

    // calculate the monthly payment and display the result, invoked when button "Calculate" is clicked
    protected void buttonCalc()
    {
        double principal = -1;
        double interestYearly = -1;
        int termYears = -1;

        // get amount, term, interest from the text field
        try
        {
            principal = Double.parseDouble(txtAmount.getText());
            if (principal <= 0)
                throw new Exception();
            termYears = Integer.parseInt(txtTerm.getText());
            if (termYears <= 0)
                throw new Exception();
            interestYearly = Double.parseDouble(txtInterest.getText());
            if (interestYearly <= 0 || interestYearly >= 100)
                throw new Exception();
        }
        catch (Exception e)
        {
            if (principal <= 0)
                JOptionPane.showMessageDialog(this, "Please enter positive amount.");
            else if (termYears <= 0)
                JOptionPane.showMessageDialog(this, "Please enter positive years.");
            else if (interestYearly <= 0 || interestYearly >= 100)
                JOptionPane.showMessageDialog(this, "Please enter valid interest rate.");
            return;
        }

     }
		    /**
				     * Method to calculate monthly payment
				     * @param principal
				     * @param interestYearly
				     * @param termYears
				     * @return monthly payment
             */
		    public double calcMonthlyPayment(double principal, double interestYearly, int termYears)
		    {
		        // calculate monthly interest rate
		        double interestMonthly = interestYearly / 12.0;
		        // calculate the number of payments
		        double numberOfPayments = termYears * 12;

		        //  calculate the monthly payment and return the value
		        return (principal * interestMonthly) / (1.0 - (Math.pow((1.0 + interestMonthly), -numberOfPayments)));
		   }
			 }


Was This Post Helpful? 0
  • +
  • -

#9 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10175
  • View blog
  • Posts: 37,582
  • Joined: 27-December 08

Re: Java Payment Calculator

Posted 11 July 2011 - 12:18 PM

The error you are encountering is b/c your outer class implements the interface ActionListener, but you don't define the actionPerformed() method. Instead, you define anonymous inner classes. Below are some examples of proper ways to implement Listeners:

Example 1- Implement the interface in the outer class and add this as the ActionListener. B/c the class implements an ActionListner, it is-an ActionListener. So this (this instance of MyClass) is a valid ActionListener.
class MyClass extends JFrame implements ActionListener{

     private JButton button; 

     MyClass(){
          button = new JButton();
          button.addActionListener(this);
     } 

     public void actionPerformed(ActionEvent e){}
}



Example 2- Use an anonymous inner class and define the actionPerformed() method in-line. Note that this does not satisfy the requirement to implement the abstract method (as you are seeing in your code) if MyClass implements ActionListener.
class MyClass extends JFrame{

    private JButton button;

    MyClass(){
        button = new JButton();
        button.addActionListener(new ActionListener(){

             public void actionPerformed(ActionEvent e){}
        });
    }
}



Example 3- Use a named inner class and implement the method there.
public class MyClass extends JFrame{
    
     private JButton button;

     MyClass(){
         button = new JButton();
         button.addActionListener(new MyListener());
     }

     class MyListener implements ActionListener{
          
         public void actionPerformed(ActionEvent e){}
     }
}



Hope this helps some. :)
Was This Post Helpful? 1
  • +
  • -

#10 smohd  Icon User is offline

  • Critical Section
  • member icon


Reputation: 1752
  • View blog
  • Posts: 4,409
  • Joined: 14-March 10

Re: Java Payment Calculator

Posted 11 July 2011 - 12:20 PM

I copy your first code and add main() as pointed and run them. It works fine to me. Your updated code still has no main(). Please copy and paste your real updated code that gives you that error.
Was This Post Helpful? 1
  • +
  • -

#11 javaconfused  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 11-July 11

Re: Java Payment Calculator

Posted 11 July 2011 - 12:28 PM

Wonderful news! I have done what you have requested and it works WONDERFULLY! Now only one problem. It will not calculate.. Any suggestions?



import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.NumberFormat;
import java.util.Date;

import javax.swing.*;

public class MortgageCalculatorGUI extends JFrame
{

    // declare GUI element viariables

    // labels
    private JLabel lblAmount = new JLabel("Loan Amount: ");
    private JLabel lblTerm = new JLabel("Term (Year): ");
    private JLabel lblInterest = new JLabel("Interest Rate: %");

    // text field
    private JTextField txtAmount = new JTextField(10);
    private JTextField txtTerm = new JTextField(10);
    private JTextField txtInterest = new JTextField(10);

    // button
    private JButton btnCalc = new JButton("Calculate");
    private JButton btnReset = new JButton("Reset");

    // text area
    private JTextArea areaResult = new JTextArea(30, 10);

    // number format
    private NumberFormat fmt = NumberFormat.getCurrencyInstance();

    // constructor
    public MortgageCalculatorGUI()
    {
        super("Mortgage Calculator - PRG 421 Week 2");

        // initialize the GUI

        // set layout to borderlayout
        super.setLayout(new BorderLayout());

        // create a new panel with grid layout, 4 rows 2 columns
        JPanel pnInput = new JPanel(new GridLayout(4, 2));

        // add labels and text fields to panel
        pnInput.add(lblAmount);
        pnInput.add(txtAmount);
        pnInput.add(lblTerm);
        pnInput.add(txtTerm);
        pnInput.add(lblInterest);
        pnInput.add(txtInterest);
        pnInput.add(btnCalc);
        pnInput.add(btnReset);

        // add action listener to buttons
        btnCalc.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                buttonCalc();
            }
        });
        btnReset.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                buttonreset();
            }
        });

        // add panel to north
        add(pnInput, BorderLayout.NORTH);

        // add result area to center
        add(new JScrollPane(areaResult), BorderLayout.CENTER);

        // set property
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setSize(400, 300);

    } // end contructor

    // reset the text, invoked when button reset is clicked
    protected void buttonreset()
    {
        txtAmount.setText("");
        txtTerm.setText("");
        txtInterest.setText("");
        areaResult.setText("");
    } // end buttonreset

    // calculate the monthly payment and display the result, invoked when button "Calculate" is clicked
    protected void buttonCalc()
    {
        double principal = -1;
        double interestYearly = -1;
        int termYears = -1;

        // get amount, term, interest from the text field
        try
        {
            principal = Double.parseDouble(txtAmount.getText());
            if (principal <= 0)
                throw new Exception();
            termYears = Integer.parseInt(txtTerm.getText());
            if (termYears <= 0)
                throw new Exception();
            interestYearly = Double.parseDouble(txtInterest.getText());
            if (interestYearly <= 0 || interestYearly >= 100)
                throw new Exception();
        }
        catch (Exception e)
        {
            if (principal <= 0)
                JOptionPane.showMessageDialog(this, "Please enter positive amount.");
            else if (termYears <= 0)
                JOptionPane.showMessageDialog(this, "Please enter positive years.");
            else if (interestYearly <= 0 || interestYearly >= 100)
                JOptionPane.showMessageDialog(this, "Please enter valid interest rate.");
            return;
        }

     }
		    /**
				     * Method to calculate monthly payment
				     * @param principal
				     * @param interestYearly
				     * @param termYears
				     * @return monthly payment
             */
		    public double calcMonthlyPayment(double principal, double interestYearly, int termYears)
		    {
		        // calculate monthly interest rate
		        double interestMonthly = interestYearly / 12.0;
		        // calculate the number of payments
		        double numberOfPayments = termYears * 12;

		        //  calculate the monthly payment and return the value
		        return (principal * interestMonthly) / (1.0 - (Math.pow((1.0 + interestMonthly), -numberOfPayments)));
		   }

/**
     * The main method
     * @param args
     */
    public static void main(String[] args)
    {
        MortgageCalculatorGUI window = new MortgageCalculatorGUI();
        window.setSize(500, 500);
        window.setLocationRelativeTo(null); // move the window to the center of the screen
        window.setVisible(true);
        }
}


Was This Post Helpful? 0
  • +
  • -

#12 smohd  Icon User is offline

  • Critical Section
  • member icon


Reputation: 1752
  • View blog
  • Posts: 4,409
  • Joined: 14-March 10

Re: Java Payment Calculator

Posted 11 July 2011 - 12:39 PM

Because there is no any calculation done in buttonCalc(). After input your data you have to do your calculations there. I dont know your formula which you are using, but you have to do calculation.
Look at your method:
 protected void buttonCalc() {
        double principal = -1;
        double interestYearly = -1;
        int termYears = -1;

        // get amount, term, interest from the text field
        try {
            principal = Double.parseDouble(txtAmount.getText());
            if (principal <= 0) {
                throw new Exception();
            }
            termYears = Integer.parseInt(txtTerm.getText());
            if (termYears <= 0) {
                throw new Exception();
            }
            interestYearly = Double.parseDouble(txtInterest.getText());
            if (interestYearly <= 0 || interestYearly >= 100) {
                throw new Exception();
            }
        } catch (Exception e) {
            if (principal <= 0) {
                JOptionPane.showMessageDialog(this, "Please enter positive amount.");
            } else if (termYears <= 0) {
                JOptionPane.showMessageDialog(this, "Please enter positive years.");
            } else if (interestYearly <= 0 || interestYearly >= 100) {
                JOptionPane.showMessageDialog(this, "Please enter valid interest rate.");
            }
            return;
        }
// You have to do your calculation here after getting all inputs correctly and then display output
    } 

Was This Post Helpful? 1
  • +
  • -

#13 javaconfused  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 11-July 11

Re: Java Payment Calculator

Posted 11 July 2011 - 12:44 PM

So the next set of commands beneath that section do not calculate?
Was This Post Helpful? 0
  • +
  • -

#14 smohd  Icon User is offline

  • Critical Section
  • member icon


Reputation: 1752
  • View blog
  • Posts: 4,409
  • Joined: 14-March 10

Re: Java Payment Calculator

Posted 11 July 2011 - 01:00 PM

What do you mean? You have to do your calculation there. What you have done there is just taking value entered by user and check if they are correct or not! You have to implement your formula for calculating what you want to calculate
Was This Post Helpful? 1
  • +
  • -

#15 javaconfused  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 11-July 11

Re: Java Payment Calculator

Posted 11 July 2011 - 02:13 PM

Ok... this is the expected calculation.
Rate Calculation = ((rate/12) /100)
Term Calculation = term * 12
Payment Calculation = amount * (rate calculation/(1-Math.pow(1+ rate calculation, -Term Calculation)))

This is the code I've done so far as requested to fix my errors

import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.NumberFormat;
import java.util.Date;

import javax.swing.*;

public class MortgageCalculatorGUI extends JFrame
{
    // declare GUI element viariables

    // labels
    private JLabel lblAmount = new JLabel("Loan Amount: ");
    private JLabel lblTerm = new JLabel("Term (Year): ");
    private JLabel lblInterest = new JLabel("Interest Rate: %");

    // text field
    private JTextField txtAmount = new JTextField(10);
    private JTextField txtTerm = new JTextField(10);
    private JTextField txtInterest = new JTextField(10);

    // button
    private JButton btnCalc = new JButton("Calculate");
    private JButton btnReset = new JButton("Reset");

    // text area
    private JTextArea areaResult = new JTextArea(30, 10);

    // number format
    private NumberFormat fmt = NumberFormat.getCurrencyInstance();

    // constructor
    public MortgageCalculatorGUI()
    {
        super("Mortgage Calculator - PRG 421 Week 2");

        // initialize the GUI

        // set layout to borderlayout
        super.setLayout(new BorderLayout());

        // create a new panel with grid layout, 4 rows 2 columns
        JPanel pnInput = new JPanel(new GridLayout(4, 2));

        // add labels and text fields to panel
        pnInput.add(lblAmount);
        pnInput.add(txtAmount);
        pnInput.add(lblTerm);
        pnInput.add(txtTerm);
        pnInput.add(lblInterest);
        pnInput.add(txtInterest);
        pnInput.add(btnCalc);
        pnInput.add(btnReset);

        // add action listener to buttons
        btnCalc.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                buttonCalc();
            }
        });
        btnReset.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                buttonreset();
            }
        });

        // add panel to north
        add(pnInput, BorderLayout.NORTH);

        // add result area to center
        add(new JScrollPane(areaResult), BorderLayout.CENTER);

        // set property
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setSize(300, 200);

    } // end constructor

    // reset the text, invoked when button reset is clicked
    protected void buttonreset()
    {
        txtAmount.setText("");
        txtTerm.setText("");
        txtInterest.setText("");
        areaResult.setText("");
    } // end buttonreset

    // calculate the monthly payment and display the result, invoked when button "Calculate" is clicked
    protected void buttonCalc()
    {
        double principal = -1;
        double interestYearly = -1;
        int termYears = -1;

        // get amount, term, interest from the text field
        try
        {
            principal = Double.parseDouble(txtAmount.getText());
            if (principal <= 0)
                throw new Exception();
            termYears = Integer.parseInt(txtTerm.getText());
            if (termYears <= 0)
                throw new Exception();
            interestYearly = Double.parseDouble(txtInterest.getText());
            if (interestYearly <= 0 || interestYearly >= 100)
                throw new Exception();

        // calculate and display the result
           int payment = calcMonthlyPayment(principal, termYears / 100, interestYearly);
            displayMonthlyPayment(principal, termYears / 100, interestYearly, payment);
        }
        catch (Exception e)
        {
          	areaResult.setText("Error: Please try again.\n");
				         }
    }
		    /**
				     * Method to calculate monthly payment
				     * @param principal
				     * @param interestYearly
				     * @param termYears
				     * @return monthly payment
             */
		    public double calcMonthlyPayment(double principal, double interestYearly, int termYears)
		    {
		        // calculate monthly interest rate
		        double interestMonthly = interestYearly / 12.0;
		        // calculate the number of payments
		        double numberOfPayments = termYears * 12;

		        //  calculate the monthly payment and return the value
		        return (principal * interestMonthly) / (1.0 - (Math.pow((1.0 + interestMonthly), -numberOfPayments)));
		   }

      /**
	     * The main method
	     * @param args
	     */
	    public static void main(String[] args)
	    {
	        MortgageCalculatorGUI window = new MortgageCalculatorGUI();
	        window.setSize(500, 500);
	        window.setLocationRelativeTo(null); // move the window to the center of the screen
	        window.setVisible(true);
	  }
	}



Here is the error I'm getting:
calcMonthlyPayment(double,double,int) in MortgageCalculatorGUI cannot be applied to(double,int,double)
double payment = calcMonthlyPayment (principal, termYears/100, interestYearly);
//the ^ symbol is under the "c" in calcMonthlyPayment

cannot find symbol
symbol : method displayMonthlyPayment (double, int,double,double
location: class mortgageCalculatorGUI
displayMonthlyPayment(principal, termYears/100, interestYearly, payment);
//the ^ symbol is under the "d" in displayMonthlyPayment

I do appreciate the time you all are giving me for this issue, I assure you understanding this is all I want. I've been reading more then my mind allows and I am still a little lost on making thing "mesh". Again, thank you
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2