getting cannot find symbol

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • karinmorena
    New Member
    • Feb 2008
    • 2

    getting cannot find symbol

    I'm having 4 errors, I'm very new at this and I would appreciate your input. The error I get is:
    Week5MortgageGU I.java:151:cann ot find symbol
    symbol: method allInterest(dou ble,double,doub le)
    Location: class Week5MortgageGU I
    Week5MortgageLo gic allint = logic.allIntere st(amount, term[x], rate[x]);


    Week5MortgageGU I.java:152:cann ot find symbol
    symbol: method allInterest(dou ble,double,doub le)
    Location: class Week5MortgageGU I
    textarea.append (logic.calculat eMortgage(amoun t, term[x], rate[x]));

    Week5MortgageGU I.java:156:cann ot find symbol
    symbol: class ApplePie
    Location: class Week5MortgageGU I
    pie = new ApplePie(2);

    Week5MortgageGU I.java:157:cann ot find symbol
    symbol: method addSlice(java.a wt.Color,double )
    Location: class java.awt.event. ActionEvent
    pie.addSlice(Co lor.red, allint);
    ^
    Week5MortgageGU I.java:158:cann ot find symbol
    symbol: method addSlice(java.a wt.Color,double )
    Location: class java.awt.event. ActionEvent
    pie.addSlice(Co lor.green, amount);
    ^
    Week5MortgageGU I.java:160:cann ot find symbol
    symbol: method addSlice(java.a wt.Color,double )
    Location: class java.awt.Contai ner
    jpie.getContent Pane().add(pie) ;
    ^

    This is the code that is getting the error. Can anyone help me out? =)

    [PHP]import javax.swing.*;
    import java.awt.*;
    import java.awt.event. *;
    import java.io.*;
    import java.text.Decim alFormat;
    import java.net.URL;
    import java.awt.event. ActionEvent;


    public class Week5MortgageGU I extends JApplet implements ActionListener {

    //Declare variables and arrays
    int x;
    double amount, allint;
    String header = ("MONTH \tPAYMENT \tBALANCE \tINTEREST \n");
    String[] cases = new String[4];//Empty array
    double[] rate = new double[4];//Empty array
    double[] term = {7, 15, 30, 0};
    DecimalFormat money = new DecimalFormat(" $###,###.00");//New DecimalFormat object named 'money'
    //Set up JFrame GUI components
    JButton cal = new JButton("Calcul ate!");
    JButton ok = new JButton("Ok");
    JButton quit = new JButton("Quit") ;
    JPanel panel1 = new JPanel();
    JPanel panel2 = new JPanel();
    JPanel panel3 = new JPanel();
    JPanel panel4 = new JPanel();
    Box box1 = Box.createVerti calBox();
    Box box2 = Box.createVerti calBox();
    Box myBox = Box.createVerti calBox();
    JLabel select = new JLabel("Select loan term & rate:");
    JLabel amountlabel = new JLabel("Enter Amount: $");//Create label that directs user to enter his/her name
    JLabel termlabel = new JLabel("Enter Term: ");//Create label that directs user to enter his/her name
    JLabel ratelabel = new JLabel("Enter Rate: ");//Create label that directs user to enter his/her name
    JLabel message = new JLabel("Click Ok to continue:");
    JLabel legend = new JLabel("Pie Chart Legend:");
    JLabel space = new JLabel("-------------------------");
    JLabel allinterest;
    JLabel allprincipal;
    JTextField amounttext = new JTextField(10);//Create blank text field
    JTextField termtext = new JTextField(10);//Create blank text field
    JTextField ratetext = new JTextField(10);//Create blank text field
    JTextArea textarea = new JTextArea(8, 35);
    JScrollPane scroll = new JScrollPane(tex tarea, JScrollPane.VER TICAL_SCROLLBAR _AS_NEEDED, JScrollPane.HOR IZONTAL_SCROLLB AR_NEVER);
    JRadioButton radio1 = new JRadioButton();
    JRadioButton radio2 = new JRadioButton();
    JRadioButton radio3 = new JRadioButton();
    JRadioButton radio4 = new JRadioButton();
    ButtonGroup group = new ButtonGroup();
    Container content_pane = getContentPane( );
    JFrame jpie;

    //Declare init() method for JApplet
    public void init() {
    setSize(600, 400);//Set JApplet size
    FlowLayout flow = new FlowLayout();//Create FlowLayout object called 'nameflow'
    content_pane.se tLayout(flow);//Set content_pane layout format to 'flow' object
    this.readRates( "rates.txt" );//Populate 'rate' array from the values contained within file "rates.txt" - see method below
    cases[0] = "7 year at " + rate[0] + "%";//Populate 'cases' array
    cases[1] = "15 year at " + rate[1] + "%";
    cases[2] = "30 year at " + rate[2] + "%";
    cases[3] = "Enter my own term & rate";
    radio1.setText( cases[0]);//Set up radio buttons
    radio2.setText( cases[1]);
    radio3.setText( cases[2]);
    radio4.setText( cases[3]);
    amounttext.addA ctionListener(t his);//Add the action listeners
    termtext.addAct ionListener(thi s);
    ratetext.addAct ionListener(thi s);
    cal.addActionLi stener(this);
    ok.addActionLis tener(this);
    quit.addActionL istener(this);
    radio1.addActio nListener(this) ;
    radio2.addActio nListener(this) ;
    radio3.addActio nListener(this) ;
    radio4.addActio nListener(this) ;
    group.add(radio 1);//Add radio buttons to button group
    group.add(radio 2);
    group.add(radio 3);
    group.add(radio 4);
    box1.add(select );//Add radio buttons to vertical box #1
    box1.add(radio1 );
    box1.add(radio2 );
    box1.add(radio3 );
    box1.add(radio4 );
    box2.add(termla bel);//Add these GUI components to vertical box #2
    box2.add(termte xt);
    box2.add(ratela bel);
    box2.add(ratete xt);
    panel1.add(amou ntlabel);//Add GUI components to panel #1
    panel1.add(amou nttext);
    panel1.add(box1 );
    panel2.add(cal) ;//Add GUI components to panel #2
    panel3.add(scro ll);//Add GUI components to panel #3
    content_pane.ad d(panel1);//Add these panels to the content pane
    content_pane.ad d(panel2);
    content_pane.ad d(panel3);
    textarea.append (header);
    panel4.add(mess age);//Add GUI components to panel #4 but don't add panel to content pane yet
    panel4.add(ok);
    panel4.add(quit );
    this.setVisible (true);//Make the JFrame visible to the user
    }


    //Declare actionPerformed method to receive & process ActionListener event (user input)
    public void actionPerformed (ActionEvent response) {
    Object rspname = response.getSou rce();//Get response source

    try {
    //Rearrange display to accept user-defined term & rate if radio4 is selected
    if (radio4.isSelec ted() == true) {
    panel1.add(box2 );
    content_pane.va lidate();
    }
    //Remove text labels & fields for user-defined term & rate if radio4 is not selected
    if (radio4.isSelec ted() == false) {
    panel1.remove(b ox2);
    content_pane.va lidate();
    }

    if (rspname == cal) {
    //Obtain user-defined term & rate from termtext & ratetext fields
    if (rspname == cal && radio4.isSelect ed() == true) {
    term[3] = Double.parseDou ble(termtext.ge tText());//Parse double from String
    rate[3] = Double.parseDou ble(ratetext.ge tText());
    x = 3;
    }
    if (rspname == cal && radio3.isSelect ed() == true) {
    x = 2;
    }
    if (rspname == cal && radio2.isSelect ed() == true) {
    x = 1;
    }
    if (rspname == cal && radio1.isSelect ed() == true) {
    x = 0;
    }
    //Throw this special Exception if the user fails to make a selection
    if (radio1.isSelec ted() == false && radio2.isSelect ed() == false && radio3.isSelect ed() == false && radio4.isSelect ed() == false) {
    throw new Exception("Sele ctionError");
    }
    amount = Double.parseDou ble(amounttext. getText());//pull amount data from amounttext field
    Week5MortgageGU I logic = new Week5MortgageGU I();
    allint = logic.allIntere st(amount, term[x], rate[x]);//Calculate total interest paid over life of loan.
    textarea.append (logic.calculat eMortgage(amoun t, term[x], rate[x]));//Obtain the amortization table from the logic class

    ActionEvent pie ;

    pie = new ApplePie(2);//Create ApplePie object (pie chart)
    pie.addSlice(Co lor.red, allint);//Red pie slice = allint value
    pie.addSlice(Co lor.green, amount);//Green pie slice = amount value
    jpie = new JFrame("Interes t vs. Principal");//Create JFrame to hold pie chart
    jpie.getContent Pane().add(pie) ;//Add pie chart to JFrame
    jpie.pack();//Causes this Window to be sized to fit the preferred size and layouts of its subcomponents.
    jpie.setSize(25 0, 250);//Set size of new JFrame window
    jpie.setVisible (true);//Make the JFrame visible to the user

    allinterest = new JLabel("RED - Total interest paid: " + money.format(al lint));//Pie labels
    allprincipal = new JLabel("GREEN - Total principal paid: " + money.format(am ount));//Pie labels
    myBox.add(legen d);//Add labels to vertical box
    myBox.add(space );
    myBox.add(allin terest);
    myBox.add(allpr incipal);
    content_pane.ad d(myBox);//Add vertical box to content pane
    content_pane.ad d(panel4);//Add panel4 to content pane
    content_pane.va lidate();//Refresh the JPanel
    }

    if (rspname == quit) {//Selecting Quit disposes of the jpie & current JFrame
    jpie.dispose();
    jpie.setVisible (false);//Set visible-false to avoid memory leaks
    this.setVisible (false);
    }

    if (rspname == ok) {//Selecting Ok clears the populated fields
    jpie.dispose();//Dispose of the jpie JFrame
    jpie.setVisible (false);//Set visible-false to avoid memory leaks
    textarea.setTex t("");
    amounttext.setT ext("");
    termtext.setTex t("");
    ratetext.setTex t("");
    this.remove(myB ox);
    this.repaint();
    this.validate() ;
    myBox.remove(le gend);
    myBox.remove(sp ace);
    myBox.remove(al linterest);
    myBox.remove(al lprincipal);
    myBox.revalidat e();
    }
    } //Take these actions when an Exception occurs
    catch (NumberFormatEx ception e)//Specific Exception
    {
    textarea.append ("Invalid Entry - The amount must be a positive number!\n" + e.toString() + "\n");
    } catch (Exception e)//More general exception
    {
    if (e.getMessage() == "SelectionError ") {//Specify exception message
    textarea.append ("Invalid Entry - Please select term & rate of your loan\n" + e.toString() + "\n");
    } else {//Other general exceptions
    textarea.append ("Invalid Entry - The amount must be a positive number!\n" + e.toString() + "\n");
    }
    } catch (Throwable e)//Catch everything else
    {
    textarea.append ("Invalid Entry!\n" + e.toString() + "\n");
    }

    }


    private void readRates(Strin g filename) {
    try {
    URL codeBase = getCodeBase();
    URL url = null;
    int index = 0;
    url = new URL(codeBase, filename);
    BufferedReader reader = new BufferedReader( new InputStreamRead er(url.openStre am()));
    String line = reader.readLine ();
    while (line != null) {
    rate[index] = Double.parseDou ble(line);
    line = reader.readLine ();
    index++;
    }
    } catch (Exception e) {
    textarea.append ("Could not read from file " + filename);
    }
    }

    //Create an instance of the Week5MortgageGU I (this) class
    public static void main(String[] args,Week5Mortg ageGUI Week5MortgageGU I) {
    Week5MortgageGU I = new Week5MortgageGU I();
    }


    }
    [/PHP]
  • karinmorena
    New Member
    • Feb 2008
    • 2

    #2
    Can anyone please help me? I would really appreciate it!

    Comment

    • BigDaddyLH
      Recognized Expert Top Contributor
      • Dec 2007
      • 1216

      #3
      Originally posted by karinmorena
      I'm having 4 errors, I'm very new at this and I would appreciate your input. The error I get is:
      Week5MortgageGU I.java:151:cann ot find symbol
      symbol: method allInterest(dou ble,double,doub le)
      Location: class Week5MortgageGU I
      Week5MortgageLo gic allint = logic.allIntere st(amount, term[x], rate[x]);
      That error says it all. You wrote:
      [CODE=Java]
      Week5MortgageGU I logic = new Week5MortgageGU I();
      allint = logic.allIntere st(amount, term[x], rate[x]);
      [/CODE]
      That line only makes sense if class Week5MortageLog ic had a method named allInterest, which it doesn't.

      What did you think that line was going to do? Also, Week5MortageLog ic is an applet, and you are instantiating the class within its init method, which doesn't make any sense, or am I missing something?

      Comment

      Working...