11 Replies - 887 Views - Last Post: 26 March 2010 - 06:54 PM Rate Topic: -----

#1 LadiPrather   User is offline

  • New D.I.C Head

Reputation: -4
  • View blog
  • Posts: 23
  • Joined: 12-February 10

11 errors on Java program

Posted 24 March 2010 - 12:25 PM

Edited by Dogstopper: By 19 posts, you should know how to :code:

If this continues, you may have issues with the moderating staff. Thanks

original post:
____________________________________________________________

I am doing this calculator I have added and deleted and still get 11 errors can someone look at this and please help.
import java.text.*;
import java.math.*;
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.lang.String;


public class Main {

    /**
     * @param args the command line arguments
     */
 public class MortgageCalculator5 {
 }
    public static void main(String[] args) {
      JFrame window = new MortCalculGUI();
      window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      window.setVisible(true);
    }
}
class MortCalcu5GUI extends JFrame implements ActionListener {

        // Declare GUI function variables
    protected JButton bCalc7, bCalc15, bCalc30, bClear, bExit;
    protected JLabel labelPayment, labelLoanAmount, labelTitle, labelInstructions, labelAmortTable;
    protected JTextField feildPayment, fieldLoanAmount;
    protected JTextArea areaAmortTable;

    //Declare variables and loan array and initialize with values
    double InterestPaid, PrinciplePaid, Balance, monthlyPay, loanAmount;
   int[] loanTerm = {7, 15, 30}; //loan term for 7 years, 15 years, and 30 years
   double[] intRate = {5.35, 5.50, 5.75};//interest rates for 7 years, 15 years, and 30 years
   double loanAmt = loanAmount;
   


   public void actionPerformed (ActionEvent e) {

       //Perform actions based upon which button is pressed (provides looping function)
          if ("Calculate7".equals(e.getActionCommand())) {
              DecimalFormat decimalPlaces = new DecimalFormat ("0.00");
              NumberFormat currency = NumberFormat.getCurrencyInstance();
              double paymentAmount = CalculatePayment7();
              fieldPayment.setText ("" + (currency.format(paymentAmount)));
              areaAmortTable.append("Payment # \t Remaining Balance \t Interest Pain\n");
              loanAmt = Double.parseDouble (fieldLoanAmount.getText());
              for (int x = 1; x<=(loanTerm[0]*12); x++)//Loop through all monthly payments for each loan
              {
                  Balance = loanAmt;//Set Balance to Loan Amount
             //Calculations on monthly payment
                  InterestPaid = (((intRate[0]/100.0)/12.0)*Balance);//Monthly Interest paid
                  PrinciplePaid = (paymentAmount-InterestPaid);//Applied toward principle
                  loanAmt = (Balance-PrinciplePaid);//loan balance after payment
                  areaAmortTable.append (x + "\t" + currency.format (loanAmt) + " \t\t" + currency.format(InterestPaid) +"n");
                   }
              if (Balance <= 0)//ending statement, balance at $0.00
              {
                  areaAmortTable.append ("\tRemaining balance = $0.00");
                  //paymentNumber = 0;
                  //InterestedPaid = 0.0;
              }

          }
          else if ("Calculate15".equals(e.getActionCommand()))
          {
              DecimalFormat decimalPlaces = new DecimalFormat ("0.00");
              NumberFormat currency = NumberFormat.getCurrencyInstance();
              double paymentAmount = CalculatePayment15();
              fieldPayment.setText ("" + (currency.format(paymentAmount)));
              areaAmortTable.append ("Payment # \t Remaining Balance \t Interest Paid\n");
              loanAmt = Double.parseDouble(fieldLoanAmount.getText());
              for (int x = 1; x<=(loanTerm[1]*12); x++)//Loop through all monthly payment for each loan
              {
                  Balance = loanAmt;
             //Calculation on monthly payment
                  InterestPaid = ((intRate[1]/100/12)*Balance);//Monthly Interest paid
                  PrinciplePaid = (paymentAmount-InterestPaid);//Applied toward principle
                  loanAmt = ((Balance-PrinciplePaid));//loan balance after payment
                  areaAmortTable.append (x + '\t' + currency.format (loanAmt) + "\t\t" + currency.format (InterestPaid)+ '\n');
              }
              if (loanAmt <= 0)//ending statement, blance at $0.00
              {
                  areaAmortTable.append ("\tRemaining balance = $0.00");
                  //paymentNumber =0;
                  //InterestPaid = 0.0;
              }
          }
          else if ("calculate30".equals(e.getActionCommand()))
          {
              DecimalFormat decimalPlaces = new DecimalFormat("0.00");
              NumberFormat currency = NumberFormat.getCurrencyInstance();
              double paymentAmount = CalculatePayment30();
              fieldPayment.setText ("" + (currency.format (paymentAmount)));
              areaAmortTable.append ("payment # \t Remaining Balance \t Interest Paid\n");
              loanAmt = Double.parseDouble (fieldLoanAmount.getText());
              for (int x = 1; x<=(loanTerm[2]*12); x++)//Loop through all monthly payments for each loan
              {
                  Balance = loanAmt;
            //Calulations on monthly payments
                  InterestPaid = ((intRate[2]/100/12)*Balance);//Monthly Interest Paid
                  PrinciplePaid = (paymentAmount-InterestPaid);//Applied toward principle
                  areaAmortTable.append (x + "\t" + currency.format(loanAmt) + "\t\t" + currency.format(InterestPaid)+"\n");
              }
              if (loanAmt <= 0)//ending statement, balance at $0.00
              {
                 areaAmortTable.append ("\tRemaining balance = $0.00");
                 //paymentNumber = 0;
                 //InterstPaid =0.0;
              }

              }
          else if ("Clear".equals(e.getActionCommand()))
          {
              ClearFields();
          }
          else
          {
              //end and close application
              System.exit(0);
          }
          }
   public double CalculatePayment7 ()
   {
       //Check for numeric input
       try
       {
           //Perform payment calculations if input is valid
           fieldPayment.setText ("");
           double Payment = (loanAmount()* (intRate[0]/100/12)) / (1- Math.pow(1/(1 + (intRate[0]/100/12)), loanTerm[0]*12));
           return Payment;
       }
       catch (NumberFormatException event)
       {
           //Display error message if input is invalid
           JOptionPane.showMessageDialog(null, "Invalid Entry!\nPlease enter only numeric values!!","ERROR",
                   JOptionPane.ERROR_MESSAGE);
           return 0;
       }
   }
   public double CalculationPayment15()
   {
       //Check for valid input
       try
       {
           //Perform payment calculations if input is valid
           fieldpayment.setText ("");
           double Payment = (loanAmount( )* (intRate[1]/100/12)) / (1 - Math.pow(1/(1 +(intRate[1]/100/12)),loanTerm[1]*12));
           return Payment;
       }
       catch (NumberFormatException event)
       {
       //Display erroe message if input is invalid
           JOptionPane.showMessageDialog(null, "Invalid entry!\nPlease enter only numeric values!!",
                   "ERROR", JOptionPane.ERROR_MESSAGE);
           return 0;
       }
   }
   public double CalculatePayment30()
   {
       //Check for vilid numeric input
       try
       {
           //Perform payment calculation if input in valid
           fieldPayment.setText ("");
           double Payment = (loanAmount()* (intRate[2]/100/12))/(1 - Math.pow (1/(1 + (intRate[2]/100/12)), loanTerm[2]*12));
           return Payment;
       }
       catch (NumberFormatException event)
       {
         //Display error message if input is invalid
           JOptionPane.showMessageDialog(null, "Invalid Entry!\nPlease enter only numeric values!!",
                   "ERROR", JOptionPane.ERROR_MESSAGE);
           return 0;
       }
   }
   public void ClearFields()
   {
          //Set all text to blank
       fieldPayment.setText ("");
       fieldLoanAmount.setText ("");
       areaAmortTable.setText ("");
   }
   public MortCalcu5GUI ();
   {
       //Set up and initialize buttons for GUI
       bCalc7 = new JButton ("7 Year, 5.32%");
       bCalc7.setActionCommand ("Calculate7");
       bCalc15 = new JButton ("15 Years, 5.50%");
       bCalc15.setActionCommand ("Calculate15");
       bCalc30 = new JButton ("30 Years, 5.75%");
       bCalc30.setActionCommand ("Calculate30");
       bClear = new JButton ("Clear All Fields");
       bClear.setActionCommand ("Clear");
       bExit = new JButton ("Exit Program");
       bExit.setActionCommand ("Exit");

       //Set up labels and field sizes for GUI
       labelTitle = new JLabel ("McBride Mortgage Calculator V3.5");
       labelInstructions = new JLabel ("Enter the amount of the Loan and then choose the term/rate of the loan.");
       labelPayment = new JLabel ("Monthly Payment:");
       labelLoanAmount = new JLabel ("Amount of Loan:");
       fieldPayment = new JTextField ("", 12);
       fieldLoanAmount = new JTextField ("", 10);
       labelAmortTable = new JLabel ("Amortization Table");
       areaAmortTable = new JTextArea (10, 300);

       JScrollPane scrollPane = new JScrollPane (areaAmortTable, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
               JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);

         //Set up listerners for each button
       bCalc7.addActionListener (this);
       bCalc15.addActionListener (this);
       bCalc30.addActionListener (this);
       bClear.addActionListener (this);
       bExit.addActionListener (this);

        }
   public double loanAmount ()
   {
      double loanAmount = Double.parseDouble (fieldLoanAmount.getText());
      return loanAmount;

   }


}

This post has been edited by Dogstopper: 24 March 2010 - 01:45 PM


Is This A Good Question/Topic? 0
  • +

Replies To: 11 errors on Java program

#2 macosxnerd101   User is offline

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12800
  • View blog
  • Posts: 45,992
  • Joined: 27-December 08

Re: 11 errors on Java program

Posted 24 March 2010 - 12:47 PM

Please, :code:
It would also help if you could specifically describe your errors. Feel free to post any compiler errors.
Was This Post Helpful? 0
  • +
  • -

#3 LadiPrather   User is offline

  • New D.I.C Head

Reputation: -4
  • View blog
  • Posts: 23
  • Joined: 12-February 10

Re: 11 errors on Java program

Posted 25 March 2010 - 01:08 PM

Here are the errors

Compiling 1 source file to C:\Users\Diane Prather\Documents\NetBeansProjects\feedreader-suite\MortgageCalculator5\build\classes

C:\Users\Diane Prather\Documents\NetBeansProjects\feedreader-suite\MortgageCalculator5\src\mortgagecalculator5\Main.java:30: cannot find symbol

symbol : class MortCalculGUI
location: class mortgagecalculator5.Main
JFrame window = new MortCalculGUI();
C:\Users\Diane Prather\Documents\NetBeansProjects\feedreader-suite\MortgageCalculator5\src\mortgagecalculator5\Main.java:58: cannot find symbol

symbol : variable fieldPayment
location: class mortgagecalculator5.MortCalcu5GUI
fieldPayment.setText ("" + (currency.format(paymentAmount)));
C:\Users\Diane Prather\Documents\NetBeansProjects\feedreader-suite\MortgageCalculator5\src\mortgagecalculator5\Main.java:82: cannot find symbol

symbol : method CalculatePayment15()
location: class mortgagecalculator5.MortCalcu5GUI
double paymentAmount = CalculatePayment15();
C:\Users\Diane Prather\Documents\NetBeansProjects\feedreader-suite\MortgageCalculator5\src\mortgagecalculator5\Main.java:83: cannot find symbol

symbol : variable fieldPayment
location: class mortgagecalculator5.MortCalcu5GUI
fieldPayment.setText ("" + (currency.format(paymentAmount)));
C:\Users\Diane Prather\Documents\NetBeansProjects\feedreader-suite\MortgageCalculator5\src\mortgagecalculator5\Main.java:107: cannot find symbol

symbol : variable fieldPayment
location: class mortgagecalculator5.MortCalcu5GUI
fieldPayment.setText ("" + (currency.format (paymentAmount)));
C:\Users\Diane Prather\Documents\NetBeansProjects\feedreader-suite\MortgageCalculator5\src\mortgagecalculator5\Main.java:142: cannot find symbol

symbol : variable fieldPayment
location: class mortgagecalculator5.MortCalcu5GUI
fieldPayment.setText ("");
C:\Users\Diane Prather\Documents\NetBeansProjects\feedreader-suite\MortgageCalculator5\src\mortgagecalculator5\Main.java:160: cannot find symbol

symbol : variable fieldpayment
location: class mortgagecalculator5.MortCalcu5GUI
fieldpayment.setText ("");
C:\Users\Diane Prather\Documents\NetBeansProjects\feedreader-suite\MortgageCalculator5\src\mortgagecalculator5\Main.java:178: cannot find symbol

symbol : variable fieldPayment
location: class mortgagecalculator5.MortCalcu5GUI
fieldPayment.setText ("");
C:\Users\Diane Prather\Documents\NetBeansProjects\feedreader-suite\MortgageCalculator5\src\mortgagecalculator5\Main.java:193: cannot find symbol

symbol : variable fieldPayment
location: class mortgagecalculator5.MortCalcu5GUI
fieldPayment.setText ("");
C:\Users\Diane Prather\Documents\NetBeansProjects\feedreader-suite\MortgageCalculator5\src\mortgagecalculator5\Main.java:197: missing method body, or declare abstract
public MortCalcu5GUI ();

C:\Users\Diane Prather\Documents\NetBeansProjects\feedreader-suite\MortgageCalculator5\src\mortgagecalculator5\Main.java:216: cannot find symbol

symbol : variable fieldPayment
location: class mortgagecalculator5.MortCalcu5GUI
fieldPayment = new JTextField ("", 12);
11 errors
C:\Users\Diane Prather\Documents\NetBeansProjects\feedreader-suite\MortgageCalculator5\nbproject\build-impl.xml:413: The following error occurred while executing this line:

C:\Users\Diane Prather\Documents\NetBeansProjects\feedreader-suite\MortgageCalculator5\nbproject\build-impl.xml:199: Compile failed; see the compiler error output for details.
BUILD FAILED (total time: 2 seconds)

This post has been edited by LadiPrather: 25 March 2010 - 05:21 PM

Was This Post Helpful? -1
  • +
  • -

#4 xor-logic   User is offline

  • HAL9000 was an Apple product
  • member icon

Reputation: 128
  • View blog
  • Posts: 767
  • Joined: 04-February 10

Re: 11 errors on Java program

Posted 25 March 2010 - 01:57 PM

View PostLadiPrather, on 24 March 2010 - 06:25 PM, said:

 JFrame window = new MortCalculGUI();



Your first error is because you try to instantiate the method MortCalculGUI(); as if it were a class. You actually might want to create a separate class for this, or you can just refer to the method as a method, which would be
MortCalculGUI();



Incidentally, while not a requirement, it is convention that method names begin with a lowercase.

Edit: My mistake. I was misreading the method name MortCalcu5GUI(); But you are still trying to instantiate an object of type MortCalculGUI, and I don't see this class defined anywhere.

This post has been edited by xor-logic: 25 March 2010 - 03:04 PM

Was This Post Helpful? 0
  • +
  • -

#5 macosxnerd101   User is offline

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12800
  • View blog
  • Posts: 45,992
  • Joined: 27-December 08

Re: 11 errors on Java program

Posted 25 March 2010 - 02:40 PM

@LadiPrather: If you could also properly space your errors so we can more easily read them, that would help. Feel free to just edit your last post. If you do repost, please repost your code as well. Thanks for helping us help you!
Was This Post Helpful? 0
  • +
  • -

#6 LadiPrather   User is offline

  • New D.I.C Head

Reputation: -4
  • View blog
  • Posts: 23
  • Joined: 12-February 10

Re: 11 errors on Java program

Posted 25 March 2010 - 08:36 PM

Well I guess no one is going to help me
Was This Post Helpful? -3
  • +
  • -

#7 xor-logic   User is offline

  • HAL9000 was an Apple product
  • member icon

Reputation: 128
  • View blog
  • Posts: 767
  • Joined: 04-February 10

Re: 11 errors on Java program

Posted 25 March 2010 - 08:41 PM

:angry: Read my post. Dunno what kind of help you're expecting, but we're not going to rewrite your program for you. I told you why you're getting the first error. Many times, the reason you're getting the first error listed is responsible for other errors listed, so if you fix the first, some of the others sometimes go away. So fix it, then we'll see about the others.
Was This Post Helpful? 0
  • +
  • -

#8 n8wxs   User is offline

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

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

Re: 11 errors on Java program

Posted 25 March 2010 - 08:53 PM

In addition to the errors pointed out above, you have typos:

...
protected JTextField feildPayment, fieldLoanAmount;
...
fieldPayment.setText("" + (currency.format(paymentAmount)));
...
double paymentAmount = CalculatePayment15();
...
public double CalculationPayment15() {
...
fieldpayment.setText("");
...


Was This Post Helpful? 1
  • +
  • -

#9 macosxnerd101   User is offline

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12800
  • View blog
  • Posts: 45,992
  • Joined: 27-December 08

Re: 11 errors on Java program

Posted 26 March 2010 - 06:00 AM

View PostLadiPrather, on 25 March 2010 - 11:36 PM, said:

Well I guess no one is going to help me


Keep in mind that all of us are volunteers. We will get (and have already gotten) to your post. Just be patient. :)
Was This Post Helpful? 0
  • +
  • -

#10 LadiPrather   User is offline

  • New D.I.C Head

Reputation: -4
  • View blog
  • Posts: 23
  • Joined: 12-February 10

Re: 11 errors on Java program

Posted 26 March 2010 - 03:17 PM

I am sorry I did not mean to offend anyone.
Was This Post Helpful? 0
  • +
  • -

#11 macosxnerd101   User is offline

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12800
  • View blog
  • Posts: 45,992
  • Joined: 27-December 08

Re: 11 errors on Java program

Posted 26 March 2010 - 03:38 PM

Not a problem. Just keep in mind that the more posts a thread has, the less likely our Experts are to look at it. So unless your thread is about to fall off the page, please avoid bumping. Thanks for helping us help you! :)
Was This Post Helpful? 1
  • +
  • -

#12 LadiPrather   User is offline

  • New D.I.C Head

Reputation: -4
  • View blog
  • Posts: 23
  • Joined: 12-February 10

Re: 11 errors on Java program

Posted 26 March 2010 - 06:54 PM

View Postn8wxs, on 25 March 2010 - 07:53 PM, said:

In addition to the errors pointed out above, you have typos:

...
protected JTextField feildPayment, fieldLoanAmount;
...
fieldPayment.setText("" + (currency.format(paymentAmount)));
...
double paymentAmount = CalculatePayment15();
...
public double CalculationPayment15() {
...
fieldpayment.setText("");
...


Thank that took care of the problem, I need to check and double check. It works now, just having problem with the buttons now.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1