mortgage calculator (gui)

getting an error message I don't understand

Page 1 of 1

8 Replies - 6500 Views - Last Post: 22 March 2010 - 08:39 PM Rate Topic: -----

#1 cnova1501  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 21-March 10

mortgage calculator (gui)

Posted 21 March 2010 - 09:06 PM

Write the program in Java (with a graphical user interface) and have it calculate and display the mortgage payment amount from user input of the amount of the mortgage and the user's selection from a menu of available mortgage loans:

- 7 years at 5.35%
- 15 years at 5.5%
- 30 years at 5.75%

Use an array for the mortgage data for the different loans. Display the mortgage payment amount followed by the loan balance and interest paid for each payment over the term of the loan. Allow the user to loop back and enter a new amount and make a new selection or quit. Please insert comments in the program to document the program.

Here is my code but I keep getting an error message
gui.java uses or overrides a deprecated API.
Note:Recompile with -Xlint:deprecation for details


import java.awt.*;
import java.io.*;
import java.text.*;
import java.awt.event.*;
import javax.swing.*;
import static java.lang.Math.pow;
import java.text.DecimalFormat;
import javax.swing.JTextField;
import javax.swing.border.*;
import javax.swing.JOptionPane;
import  java.io.IOException;

        public class gui extends JFrame implements ActionListener


{

                //Create Frame regions.
                  JPanel jp = new JPanel();
                  JFrame frame;
                  JLabel lLoan,lAmt,lLen;
                  JTextField tLoan,tAmt;
                  JButton bSubmit,bReset,bExit;
                  JComboBox duration;
                  Container container;
                 public void init()
          {
          initComponent();

           }

        private void initComponent()
            {

         //Create a new JFrane container.
                frame = new JFrame(" EZ Loan Company");
                container = frame.getContentPane();

        //Create the layout
                GridBagLayout gbl = new GridBagLayout();


        //Set layout on container and Handle buttons
                container.setLayout(gbl);

        //Place a component at cell location (1,1)
                GridBagConstraints gbc = new GridBagConstraints();

                String[] lenloan = { "7 Years", "15 Years", "30 Years"};

                lLoan= new JLabel("Enter loan Amount");
                lAmt =  new JLabel("A Mortgage Payment in the amount of ");  //output in red

                lLen= new JLabel("Length of loan ");
                tLoan= new JTextField(10);
                tAmt =  new  JTextField(14);

                tAmt.disable();
/*  testing these fields
                                final JTextField textfield = new JTextField( "this is a TEST" );
                                textfield.setBackground( Color.BLACK );
                                textfield.setForeground( Color.YELLOW );
                                textfield.setFont( new Font( "Dialog", Font.BOLD, 15 ) );
                                textfield.setHorizontalAlignment( JTextField.RIGHT );
                                textfield.setEnabled( true );
                                textfield.setEditable( true );
*/
                duration = new JComboBox(lenloan);
                duration.setSelectedIndex(0);
                bSubmit= new JButton("Calculate Payment");
                bReset= new JButton("Reset");
                bExit= new JButton("Exit");
                gbc.gridx = 0;
                gbc.gridy = 0;
                frame.add(lLoan,gbc);


                gbc.gridx = 1;
                gbc.gridy = 0;
                frame.add(tLoan,gbc);
                gbc.gridx = 0;
                gbc.gridy = 1;
                frame.add(lLen,gbc);
                gbc.gridx = 1;
                gbc.gridy = 1;
                frame.add(duration,gbc);
                gbc.gridx = 0;
                gbc.gridy = 2;
                frame.add(lAmt,gbc);
                gbc.gridx = 1;
                gbc.gridy = 2;
                frame.add(tAmt,gbc);
                gbc.gridx = 0;
                gbc.gridy = 3;
                frame.add(bSubmit,gbc);
                bSubmit.addActionListener(this);

                gbc.gridx = 1;
                gbc.gridy = 3;
                frame.add(bReset,gbc);
                bReset.addActionListener(this);
                gbc.gridx = 0;
                gbc.gridy = 4;
                frame.add(bExit,gbc);
                bExit.addActionListener(this);

        //Show the frame
                frame.pack();
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.setVisible(true);

  }

  public void actionPerformed(ActionEvent e)
        {

                if (e.getSource()==bSubmit)
                  {
                          System.out.println(duration.getSelectedIndex());
                          gui();
                  }

                  else  if (e.getSource()==bReset)
                  {
                          tLoan.setText("");
                          duration.setSelectedIndex(0);
                          tAmt.setText("");
                  }
                  else  if (e.getSource()==bExit)
                          System.exit(1);
        }

  public void gui()

  {
          DecimalFormat twodigits  = new DecimalFormat("$#,###.00");



          
                        System.out.println ("\t Assignment 5");
                        System.out.println ("\t EZ Loan Company ");
                        System.out.println ();


          //Array for length of loan (Term)
                  double loan = Double.parseDouble(tLoan.getText());
                  double interest=.0535;
                  double InterestRate=5.35;
                  double lengthTerm=7;
                  if(duration.getSelectedIndex()==0)
                  {
                          interest=.0535;
                          InterestRate=5.35;
                          lengthTerm=7;
                  }
                  else if(duration.getSelectedIndex()==1)
                  {
                          interest=.0550;
                          InterestRate=5.50;
                          lengthTerm=15;
                  }
                  else if(duration.getSelectedIndex()==2)
                  {
                          interest=.0575;
                          InterestRate=5.75;
                          lengthTerm=30;
                  }
                  double payment = (loan*(interest/12))/(1-(Math.pow(1/(1+(interest/12)),(lengthTerm*12))));
                  String ab=""+twodigits.format(payment);
                  tAmt.setText(ab);



  }

}


Is This A Good Question/Topic? 0
  • +

Replies To: mortgage calculator (gui)

#2 n8wxs  Icon User is offline

  • --... ...-- -.. . -. ---.. .-- -..- ...
  • member icon

Reputation: 972
  • View blog
  • Posts: 3,878
  • Joined: 07-January 08

Re: mortgage calculator (gui)

Posted 21 March 2010 - 10:22 PM

Here's the scoop! :)

disable()

So use setEnabled()

//      tAmt.disable();
        tAmt.setEnabled(false);

    /*  testing these fields


This post has been edited by n8wxs: 21 March 2010 - 10:23 PM

Was This Post Helpful? 1
  • +
  • -

#3 cnova1501  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 21-March 10

Re: mortgage calculator (gui)

Posted 22 March 2010 - 04:24 PM

Ok thank you for your help that did make it compile correctly, but when I tried to run the application I got another error
Exception in thread "main" Java.lang.NoSuchMethodError: main
which I don't understand if it compiled then how come the application doesn't work?
Was This Post Helpful? 0
  • +
  • -

#4 robhilly  Icon User is offline

  • New D.I.C Head

Reputation: 6
  • View blog
  • Posts: 46
  • Joined: 26-May 08

Re: mortgage calculator (gui)

Posted 22 March 2010 - 05:15 PM

Correct me if im wrong...but this topic is in a Javascript forum, when its obviously referring to the Java language. I know early on in learning these quirks (I experienced some of them) that it doesn't make sense. So if I can be bold for a bit:

Javascript IS NOT JAVA!!!!!!

Edit:P.S. I haven't touched the Java language in a while, but I believe your error is coming from the fact that you don't have a 'main' function as an entry point for your application. However, since you are using the Swing gui, the 'main' function may be called something else depending on the library's requirements.

Quote

Exception in thread "main" Java.lang.NoSuchMethodError: main

This post has been edited by robhilly: 22 March 2010 - 05:33 PM

Was This Post Helpful? 0
  • +
  • -

#5 n8wxs  Icon User is offline

  • --... ...-- -.. . -. ---.. .-- -..- ...
  • member icon

Reputation: 972
  • View blog
  • Posts: 3,878
  • Joined: 07-January 08

Re: mortgage calculator (gui)

Posted 22 March 2010 - 06:09 PM

View Postcnova1501, on 22 March 2010 - 03:24 PM, said:

Ok thank you for your help that did make it compile correctly, but when I tried to run the application I got another error
Exception in thread "main" Java.lang.NoSuchMethodError: main
which I don't understand if it compiled then how come the application doesn't work?



Please post your code.
Was This Post Helpful? 0
  • +
  • -

#6 cnova1501  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 21-March 10

Re: mortgage calculator (gui)

Posted 22 March 2010 - 06:26 PM

error message- Exception in thread "main" Java.lang.NoSuchMethodError: main


import java.awt.*; 
import java.io.*; 
import java.text.*; 
import java.awt.event.*; 
import javax.swing.*; 
import static java.lang.Math.pow; 
import java.text.DecimalFormat; 
import javax.swing.JTextField; 
import javax.swing.border.*; 
import javax.swing.JOptionPane; 
import  java.io.IOException; 
 
        public class gui extends JFrame implements ActionListener 
 
 
{ 
 
                //Create Frame regions. 
                  JPanel jp = new JPanel(); 
                  JFrame frame; 
                  JLabel lLoan,lAmt,lLen; 
                  JTextField tLoan,tAmt; 
                  JButton bSubmit,bReset,bExit; 
                  JComboBox duration; 
                  Container container; 
                 public void init() 
          { 
          initComponent(); 
 
           } 
 
        private void initComponent() 
            { 
 
         //Create a new JFrane container. 
                frame = new JFrame(" EZ Loan Company"); 
                container = frame.getContentPane(); 
 
        //Create the layout 
                GridBagLayout gbl = new GridBagLayout(); 
 
 
        //Set layout on container and Handle buttons 
                container.setLayout(gbl); 
 
        //Place a component at cell location (1,1) 
                GridBagConstraints gbc = new GridBagConstraints(); 
 
                String[] lenloan = { "7 Years", "15 Years", "30 Years"}; 
 
                lLoan= new JLabel("Enter loan Amount"); 
                lAmt =  new JLabel("A Mortgage Payment in the amount of ");  //output in red 
 
                lLen= new JLabel("Length of loan "); 
                tLoan= new JTextField(10); 
                tAmt =  new  JTextField(14); 
 
                tAmt.setEnabled(false); 
/*  testing these fields 
                                final JTextField textfield = new JTextField( "this is a TEST" ); 
                                textfield.setBackground( Color.BLACK ); 
                                textfield.setForeground( Color.YELLOW ); 
                                textfield.setFont( new Font( "Dialog", Font.BOLD, 15 ) ); 
                                textfield.setHorizontalAlignment( JTextField.RIGHT ); 
                                textfield.setEnabled( true ); 
                                textfield.setEditable( true ); 
*/ 
                duration = new JComboBox(lenloan); 
                duration.setSelectedIndex(0); 
                bSubmit= new JButton("Calculate Payment"); 
                bReset= new JButton("Reset"); 
                bExit= new JButton("Exit"); 
                gbc.gridx = 0; 
                gbc.gridy = 0; 
                frame.add(lLoan,gbc); 
 
 
                gbc.gridx = 1; 
                gbc.gridy = 0; 
                frame.add(tLoan,gbc); 
                gbc.gridx = 0; 
                gbc.gridy = 1; 
                frame.add(lLen,gbc); 
                gbc.gridx = 1; 
                gbc.gridy = 1; 
                frame.add(duration,gbc); 
                gbc.gridx = 0; 
                gbc.gridy = 2; 
                frame.add(lAmt,gbc); 
                gbc.gridx = 1; 
                gbc.gridy = 2; 
                frame.add(tAmt,gbc); 
                gbc.gridx = 0; 
                gbc.gridy = 3; 
                frame.add(bSubmit,gbc); 
                bSubmit.addActionListener(this); 
 
                gbc.gridx = 1; 
                gbc.gridy = 3; 
                frame.add(bReset,gbc); 
                bReset.addActionListener(this); 
                gbc.gridx = 0; 
                gbc.gridy = 4; 
                frame.add(bExit,gbc); 
                bExit.addActionListener(this); 
 
        //Show the frame 
                frame.pack(); 
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
                frame.setVisible(true); 
 
  } 
 
  public void actionPerformed(ActionEvent e) 
        { 
 
                if (e.getSource()==bSubmit) 
                  { 
                          System.out.println(duration.getSelectedIndex()); 
                          gui(); 
                  } 
 
                  else  if (e.getSource()==bReset) 
                  { 
                          tLoan.setText(""); 
                          duration.setSelectedIndex(0); 
                          tAmt.setText(""); 
                  } 
                  else  if (e.getSource()==bExit) 
                          System.exit(1); 
        } 
 
  public void gui() 
 
  { 
          DecimalFormat twodigits  = new DecimalFormat("$#,###.00"); 
 
 
 
           
                        System.out.println ("\t Assignment 5"); 
                        System.out.println ("\t EZ Loan Company "); 
                        System.out.println (); 
 
 
          //Array for length of loan (Term) 
                  double loan = Double.parseDouble(tLoan.getText()); 
                  double interest=.0535; 
                  double InterestRate=5.35; 
                  double lengthTerm=7; 
                  if(duration.getSelectedIndex()==0) 
                  { 
                          interest=.0535; 
                          InterestRate=5.35; 
                          lengthTerm=7; 
                  } 
                  else if(duration.getSelectedIndex()==1) 
                  { 
                          interest=.0550; 
                          InterestRate=5.50; 
                          lengthTerm=15; 
                  } 
                  else if(duration.getSelectedIndex()==2) 
                  { 
                          interest=.0575; 
                          InterestRate=5.75; 
                          lengthTerm=30; 
                  } 
                  double payment = (loan*(interest/12))/(1-(Math.pow(1/(1+(interest/12)),(lengthTerm*12)))); 
                  String ab=""+twodigits.format(payment); 
                  tAmt.setText(ab); 
 
 
 
  } 
 
}

Was This Post Helpful? 0
  • +
  • -

#7 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1639
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: mortgage calculator (gui)

Posted 22 March 2010 - 06:38 PM

Javascript is not Java and Java is not Javascript. Moved to Java
Was This Post Helpful? 0
  • +
  • -

#8 n8wxs  Icon User is offline

  • --... ...-- -.. . -. ---.. .-- -..- ...
  • member icon

Reputation: 972
  • View blog
  • Posts: 3,878
  • Joined: 07-January 08

Re: mortgage calculator (gui)

Posted 22 March 2010 - 07:14 PM

View Postcnova1501, on 22 March 2010 - 05:26 PM, said:

error message- Exception in thread "main" Java.lang.NoSuchMethodError: main


I meant the code with main();
Was This Post Helpful? 0
  • +
  • -

#9 Dogstopper  Icon User is offline

  • The Ninjaducky
  • member icon



Reputation: 2870
  • View blog
  • Posts: 11,025
  • Joined: 15-July 08

Re: mortgage calculator (gui)

Posted 22 March 2010 - 08:39 PM

I think the issue here is that he HAS no main method...
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1