Cannot find symbol error - Constructor

Hi Folks,
i am getting the following errors when the code is compiled. Please help! The code is as below. This code is for the laptop configuration. I have 2 classes, computer.java and Wclass.java with the WIn.java(main class)
Also, how do i read the input from the radiobutton in the action performed
WClass.java:13: cannot find symbol
symbol : constructor Computer()
location: class Computer
Computer computer = new Computer();
^
WClass.java:181: append(java.lang.String) in javax.swing.JTextArea cannot be applied to (java.lang.String,java.lang.String)
Out.append("Computer Configuration for %s\n", computer.getName()
^
WClass.java:182: append(java.lang.String) in javax.swing.JTextArea cannot be applied to (java.lang.String,float)
Out.append("Processor:\t\t\t \n", computer.getProcessor());
^
WClass.java:183: append(java.lang.String) in javax.swing.JTextArea cannot be applied to (java.lang.String,float)
Out.append("HardDisk: \t\t\t \n", computer.getHarddisk());
^
WClass.java:184: append(java.lang.String) in javax.swing.JTextArea cannot be applied to (java.lang.String,float)
Out.append("RAM: \t\t\t \n", computer.getRam());
^
WClass.java:185: append(java.lang.String) in javax.swing.JTextArea cannot be applied to (java.lang.String,float)
Out.append("ProcessorSpeed:\t\t \n", computer.getProcessorSpeed(
^
WClass.java:186: append(java.lang.String) in javax.swing.JTextArea cannot be applied to (java.lang.String,float)
Out.append("Printer: \t\t\t \n", computer.getPrinter());
^
WClass.java:187: append(java.lang.String) in javax.swing.JTextArea cannot be applied to (java.lang.String,float)
Out.append("Inbuilt Wireless LAN: \t\t\n", computer.getWireless(
^
WClass.java:188: append(java.lang.String) in javax.swing.JTextArea cannot be applied to (java.lang.String,float)
Out.append("Floppy(External):\t\t \n", computer.getFloppy());
^
WClass.java:189: append(java.lang.String) in javax.swing.JTextArea cannot be applied to (java.lang.String,float)
Out.append("DVD Writer:\t\t\t \n", computer.getDVD());
^
WClass.java:190: append(java.lang.String) in javax.swing.JTextArea cannot be applied to (java.lang.String,float)
Out.append("CD Writer :\t\t\t \n", computer.getCdw());
^
WClass.java:191: cannot find symbol
symbol : method getTotal()
location: class Computer
Out.append("Total \t\t\t \n", computer.getTotal());
^
12 errors
import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
import java.util.*;
import java.awt.event.*;
public class Computer
     private String name;
     private float Processor_cost;
     private float total_cost;
     private float harddrive_cost;
     private float ram_cost;
     private float psspeed_cost;
     private float printer_cost;
     private float wireless_cost;
     private float floppy_cost;
     private float dvd_cost;
     private float cdwriter_cost;
     float pc[] = {1000f, 700f, 650f, 1200f};
     float hd[] = {0, 100f, 150f};
     float ps[] = {0, 100f, 125f};
     float ram[] = {0, 60f};
     float aa[] = {50f, 110f};
     float drive[] = {110f, 220f, 20};
     double T = 0.0;
public Computer(String Cname, int pcost, float tcost, int hcost, float rcost,
int pscost, float prcost, float wcost, float fcost, float dvdcost, float cdrwcost)
     name = Cname;
     Processor_cost = pc[pcost];
     total_cost = tcost;
     harddrive_cost = hd[hcost];
     ram_cost = rcost;
     psspeed_cost = ps[pscost];
     printer_cost = prcost;
     wireless_cost = wcost;     
     floppy_cost = fcost;
     dvd_cost = dvdcost;
     cdwriter_cost = cdrwcost;
public void setName(String Cname)
     name = Cname;
public String getName()
     return name;
public void setProcessor(int pcost)
     Processor_cost = pc[pcost];
public float getProcessor()
     return Processor_cost;
public void setHarddisk(int hcost)
     harddrive_cost = hd[hcost];
public float getHarddisk()
     return harddrive_cost;
public void setRam(int rcost)
     ram_cost = rcost;
public float getRam()
     return ram_cost;
public void setProcessorSpeed(int pscost)
     psspeed_cost = ps[pscost];
public float getProcessorSpeed()
     return psspeed_cost;
public void setPrinter(float prcost)
     printer_cost = prcost;
public float getPrinter()
     return printer_cost;
public void setWireless(float wcost)
     wireless_cost = wcost;
public float getWireless()
     return wireless_cost;
public void setFloppy(float fcost)
     floppy_cost = fcost;
public float getFloppy()
     return floppy_cost;
public void setDVD(float dvdcost)
     dvd_cost = dvdcost;
public float getDVD()
     return dvd_cost;
public void setCdw(float cdrwcost)
     cdwriter_cost = cdrwcost;
public float getCdw()
     return cdwriter_cost;
//public String show()
//     String out;
     //return out.format();
public double Total()
     T = getProcessor() + getHarddisk() + getRam() + getProcessorSpeed() + getPrinter() + getWireless() + getFloppy() + getDVD() + getCdw();
     return T;
import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
import java.util.*;
public class WClass extends JFrame implements ActionListener
     Computer computer = new Computer();
     private JPanel P1;
     private JPanel P2;
     private JButton submit;
     private JButton clear;
     private JTextArea Out;
     private JLabel name;
     private JTextField Custname;
     private JComboBox processor;
     private JComboBox harddrive;
     private JRadioButton ram1;
     private JRadioButton ram2;
     private JRadioButton ram3;
     private JPanel radiopanel;
     private ButtonGroup radiogroup;
     private JComboBox processorsd;
     private JLabel L1;
     private JCheckBox printer;
     private JCheckBox lan;
     private JLabel L2;
     private JCheckBox fpy;
     private JCheckBox dvd;
     private JCheckBox cdrw;
     private JLabel L3;
     private JLabel L4;
     private JLabel L5;
     private JLabel L6;
     private JLabel L7;
     private JLabel L8;
     private JLabel L9;
     private Container c;
     int row;
     float prncost = 50f;
     float wlan = 110f;
     float fppy = 110f;
     float dvdw = 220f;
     float cdw = 20f;
     public WClass()
          super("Laptop Configuration");
          P1 = new JPanel();
          P1.setLayout(new GridLayout(10,2,5,10));
          P2 = new JPanel(new BorderLayout());
          name = new JLabel("Customer Name");
          P1.add(name);
          Custname = new JTextField(10);
          Custname.addActionListener(this);
          P1.add(Custname);
          L3 = new JLabel("Processor");
          P1.add(L3);
          String p[] = {"Pentium 4", "Celeron", "AMD", "Intel Centrino"};
          processor = new JComboBox(p);
          processor.setMaximumRowCount(3);
          P1.add(processor);
          L4 = new JLabel("Hard Disk");
          P1.add(L4);
          String h[] = {"30 GB", "40 GB", "60 GB"};
          harddrive = new JComboBox(h);
          harddrive.setMaximumRowCount(2);
          P1.add(harddrive);
          L5 = new JLabel("RAM");
          P1.add(L5);
          radiopanel = new JPanel();
          radiopanel.setLayout(new GridLayout(1,2));
          ram1 = new JRadioButton("256 MB", true);
          ram2 = new JRadioButton("512 MB", false);
          radiopanel.add(ram1);
          radiopanel.add(ram2);
          radiogroup = new ButtonGroup();
          radiogroup.add(ram1);
          radiogroup.add(ram2);
          P1.add(radiopanel);
          L6 = new JLabel("Processor Speed");
          P1.add(L6);
          String ps[] = {"1.8 GHz", "2.2 GHz", "2.8 GHz"};
          processorsd = new JComboBox(ps);
          processorsd.setMaximumRowCount(2);
          P1.add(processorsd);
          L1 = new JLabel("Additional Accessories");
          P1.add(L1);
          printer = new JCheckBox("Ink Jet Printer");
          lan = new JCheckBox("Inbuilt Wireless LAN");
          P1.add(printer);
          L7 = new JLabel("");
          P1.add(L7);
          P1.add(lan);
          L2 = new JLabel("Drives");
          P1.add(L2);
          fpy = new JCheckBox("Floppy(External)");
          dvd = new JCheckBox("DVD Writer");
          cdrw = new JCheckBox("CD Writer");
          P1.add(fpy);
          L8 = new JLabel("");
          P1.add(L8);
          P1.add(dvd);
          L9 = new JLabel("");
          P1.add(L9);
          P1.add(cdrw);
          c = getContentPane();
          add(P1, BorderLayout.NORTH);
          submit = new JButton("Submit");
          clear = new JButton("Clear");
          Out = new JTextArea(10,5);
          P2.add(submit, BorderLayout.WEST);
          P2.add(clear, BorderLayout.EAST);
          P2.add(Out,BorderLayout.CENTER);
          add(P2, BorderLayout.SOUTH);
     public void actionPerformed(ActionEvent event)
          if(event.getSource() == submit)
          computer.setName(name.getText());
          computer.setProcessor(processor.getSelectedIndex());
          computer.setHarddisk(harddrive.getSelectedIndex());
          //computer.setRam(radiogroup.getAccessibleContext());
          computer.setProcessorSpeed(processorsd.getSelectedIndex());
          if(printer.isSelected())
               computer.setPrinter(prncost);
          if(lan.isSelected())
               computer.setWireless(wlan);
          if(fpy.isSelected())
               computer.setFloppy(fppy);
          if(dvd.isSelected())
               computer.setDVD(dvdw);
          if(cdrw.isSelected())
               computer.setCdw(cdw);
          Out.append("Computer Configuration for %s\n", computer.getName());
          Out.append("Processor:\t\t\t \n", computer.getProcessor());
          Out.append("HardDisk: \t\t\t \n", computer.getHarddisk());
          Out.append("RAM: \t\t\t \n", computer.getRam());
          Out.append("ProcessorSpeed:\t\t \n", computer.getProcessorSpeed());
          Out.append("Printer: \t\t\t \n", computer.getPrinter());
          Out.append("Inbuilt Wireless LAN: \t\t\n", computer.getWireless());
          Out.append("Floppy(External):\t\t \n", computer.getFloppy());
          Out.append("DVD Writer:\t\t\t \n", computer.getDVD());
          Out.append("CD Writer :\t\t\t \n", computer.getCdw());
          Out.append("Total \t\t\t \n", computer.getTotal());
          if(event.getSource() == clear)
               Custname.setText("");
               Out.setText("");
               ram1 = new JRadioButton("256 MB", true);
               c.setLayout(new GridLayout(10,2,5,10));
import javax.swing.JFrame;
public class Win
     public static void main(String args[])
          WClass window = new WClass();
          window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE );
          window.setSize( 500,550);
          window.setVisible( true);
}

When you make a class, the compiler often gives you an empty constructor. The Computer class for example would have the following constructor.
public Computer(){ }This means you can write code, as you did in the third program like the following.
Computer c = new Computer();However if you write your own constructor such as:
public Computer(String Cname, int pcost, float tcost, int hcost, float rcost,
int pscost, float prcost, float wcost, float fcost, float dvdcost, float cdrwcost)Then an empty constructor is not supplied. So you must write your own if you want one or you must use the one that you created.
You can create as many constructors as you like, so long as they all take different arguments

Similar Messages

  • Cannot find symbol error.. really stuck.

    I have a class named Rectangle.java. It is in a package "Geometry" together with Point.java and Line.java. But when I try to use Rectangle.java in my main program, MyRect.java, it gives me a "cannot find symbol" error, particularly the methods and sometimes the variables. I tried compiling just my Rectangle class and it compiled fine.. And I tried the Line and Point classes on another program and it works fine... well probably because the Line and Point classes are from a book(Ivor Horton's Beginning Java 2).. I am just starting out in Java. :)
    Rectangle.java
    package Geometry;
    public class Rectangle{
        public Point[] corner = new Point[4];
        public String name;
        public Rectangle(){
            corner[0].setPoints(0,0);
            corner[1].setPoints(1,0);
            corner[2].setPoints(0,1);
            corner[3].setPoints(1,1);
            name = new String("Unknown");
        public Rectangle(double point1_x,double point1_y,double point2_x, double point2_y, String Name){
            corner[0].setPoints(point1_x, point1_y);
            corner[3].setPoints(point2_x, point2_y);
            corner[1].setPoints(point2_x, point1_y);
            corner[2].setPoints(point1_x, point2_y);
            name = new String(Name);
        public Rectangle(final Rectangle oldRect, String Name){
            corner[0] = oldRect.corner[0];
            corner[3] = oldRect.corner[3];
            corner[1] = oldRect.corner[1];
            corner[2] = oldRect.corner[2];
            name = new String(Name);
        public double getWidth(){
            return corner[0].distance(corner[1]);
        public static void printRectangle(final Rectangle rect){
            for(int i= 0;i<4;i++){
                System.out.println("Corner"+(i+1)+" X: "+rect.corner.getX()+" Corner"+(i+1)+" Y: "+rect.corner[i].getY());
    System.out.println();
    public String toString(){
    return ("Name: "+name);
    }MyRect.java
    import Geometry.*;
    public class MyRect{
        public static void main(String[] args){
            Rectangle myRect = new Rectangle(0,0,2,1);
            Rectangle copyRect = new Rectangle(myRect);
            printRectangle(myRect);
            double width = myRect.getWidth();
    }and the errors:
    MyRect.java:4: cannot find symbol
    symbol  : constructor Rectangle(double,double,double,double,java.lang.String)
    location: class Rectangle
                    Rectangle myRect = new Rectangle(0.0,0.0,2.0,1.0,"My Rectangle")
                                       ^
    MyRect.java:9: cannot find symbol
    symbol  : variable name
    location: class Rectangle
                    System.out.println(myRect.name);
                                             ^
    2 errors

    Are you sure you have posted the whole content of MyRect.java
    import Geometry.*;
    public class MyRect{
        public static void main(String[] args){
            Rectangle myRect = new Rectangle(0,0,2,1);
            Rectangle copyRect = new Rectangle(myRect);
            printRectangle(myRect);
            double width = myRect.getWidth();
    }I don't see the following error line in the code you have given.
    MyRect.java:4: cannot find symbol
    symbol  : constructor Rectangle(double,double,double,double,java.lang.String)
    location: class Rectangle
                    Rectangle myRect = new Rectangle(0.0,0.0,2.0,1.0,"My Rectangle")
                                       ^
    MyRect.java:9: cannot find symbol
    symbol  : variable name
    location: class Rectangle
                    System.out.println(myRect.name);
                                             ^
    2 errors

  • Need help with class info and cannot find symbol error.

    I having problems with a cannot find symbol error. I cant seem to figure it out.
    I have about 12 of them in a program I am trying to do. I was wondering if anyone could help me out?
    Here is some code I am working on:
    // This will test the invoice class application.
    // This program involves a hardware store's invoice.
    //import java.util.*;
    public class InvoiceTest
         public static void main( String args[] )
         Invoice invoice1 = new Invoice( "1234", "Hammer", 2, 14.95 );
    // display invoice1
         System.out.println("Original invoice information" );
         System.out.println("Part number: ", invoice1.getPartNumber() );
         System.out.println("Description: ", invoice1.getPartDescription() );
         System.out.println("Quantity: ", invoice1.getQuantity() );
         System.out.println("Price: ", invoice1.getPricePerItem() );
         System.out.println("Invoice amount: ", invoice1.getInvoiceAmount() );
    // change invoice1's data
         invoice1.setPartNumber( "001234" );
         invoice1.setPartDescription( "Yellow Hammer" );
         invoice1.setQuantity( 3 );
         invoice1.setPricePerItem( 19.49 );
    // display invoice1 with new data
         System.out.println("Updated invoice information" );
         System.out.println("Part number: ", invoice1.getPartNumber() );
         System.out.println("Description: ", invoice1.getPartDescription() );
         System.out.println("Quantity: ", invoice1.getQuantity() );
         System.out.println("Price: ", invoice1.getPricePerItem() );
         System.out.println("Invoice amount: ", invoice1.getInvoiceAmount() );
    and that uses this class file:
    public class Invoice
    private String partNumber;
    private String partDescription;
    private int quantityPurchased;
    private double pricePerItem;
         public Invoice( String ID, String desc, int purchased, double price )
              partNumber = ID;
         partDescription = desc;
         if ( purchased >= 0 )
         quantityPurchased = purchased;
         if ( price > 0 )
         pricePerItem = price;
    public double getInvoiceAmount()
         return quantityPurchased * pricePerItem;
    public void setPartNumber( String newNumber )
         partNumber = newNumber;
         System.out.println(partDescription+" has changed to part "+newNumber);
    public String getPartNumber()
         return partNumber;
    public void setDescription( String newDescription )
         System.out.printf("%s now refers to %s, not %s.\n",
    partNumber, newDescription, partDescription);
         partDescription = newDescription;
    public String getDescription()
         return partDescription;
    public void setPricePerItem( double newPrice )
         if ( newPrice > 0 )
    pricePerItem = newPrice;
    public double getPricePerItem()
    return pricePerItem;
    Any tips for helping me out?

    System.out.println("Part number:
    "+invoice1.getPartNumber;
    The + sign will concatenate invoice1.getPartNumber()
    after "Part number: " forming only one String.I added the plus sign and it gives me more errors:
    C:\>javac InvoiceTest.java
    InvoiceTest.java:16: operator + cannot be applied to java.lang.String
            System.out.println("Part number: ",   + invoice1.getPartNumber() );
                                                  ^
    InvoiceTest.java:17: cannot find symbol
    symbol  : method getPartDescription()
    location: class Invoice
            System.out.println("Description: ", + invoice1.getPartDescription() );
                                                          ^
    InvoiceTest.java:17: cannot find symbol
    symbol  : method println(java.lang.String,int)
    location: class java.io.PrintStream
            System.out.println("Description: ", + invoice1.getPartDescription() );
                      ^
    InvoiceTest.java:18: cannot find symbol
    symbol  : method getQuantity()
    location: class Invoice
            System.out.println("Quantity: ", + invoice1.getQuantity() );
                                                       ^
    InvoiceTest.java:18: cannot find symbol
    symbol  : method println(java.lang.String,int)
    location: class java.io.PrintStream
            System.out.println("Quantity: ", + invoice1.getQuantity() );
                      ^
    InvoiceTest.java:19: cannot find symbol
    symbol  : method println(java.lang.String,double)
    location: class java.io.PrintStream
            System.out.println("Price: ", + invoice1.getPricePerItem() );
                      ^
    InvoiceTest.java:20: cannot find symbol
    symbol  : method println(java.lang.String,double)
    location: class java.io.PrintStream
            System.out.println("Invoice amount: ", + invoice1.getInvoiceAmount() );
                      ^
    InvoiceTest.java:24: cannot find symbol
    symbol  : method setPartDescription(java.lang.String)
    location: class Invoice
            invoice1.setPartDescription( "Yellow Hammer" );
                    ^
    InvoiceTest.java:25: cannot find symbol
    symbol  : method setQuantity(int)
    location: class Invoice
            invoice1.setQuantity( 3 );
                    ^
    InvoiceTest.java:30: operator + cannot be applied to java.lang.String
            System.out.println("Part number: ", + invoice1.getPartNumber() );
                                                ^
    InvoiceTest.java:31: cannot find symbol
    symbol  : method getPartDescription()
    location: class Invoice
            System.out.println("Description: ", + invoice1.getPartDescription() );
                                                          ^
    InvoiceTest.java:31: cannot find symbol
    symbol  : method println(java.lang.String,int)
    location: class java.io.PrintStream
            System.out.println("Description: ", + invoice1.getPartDescription() );
                      ^
    InvoiceTest.java:32: cannot find symbol
    symbol  : method getQuantity()
    location: class Invoice
            System.out.println("Quantity: ", + invoice1.getQuantity() );
                                                       ^
    InvoiceTest.java:32: cannot find symbol
    symbol  : method println(java.lang.String,int)
    location: class java.io.PrintStream
            System.out.println("Quantity: ", + invoice1.getQuantity() );
                      ^
    InvoiceTest.java:33: cannot find symbol
    symbol  : method println(java.lang.String,double)
    location: class java.io.PrintStream
            System.out.println("Price: ", + invoice1.getPricePerItem() );
                      ^
    InvoiceTest.java:34: cannot find symbol
    symbol  : method println(java.lang.String,double)
    location: class java.io.PrintStream
            System.out.println("Invoice amount: ", + invoice1.getInvoiceAmount() );
                      ^
    16 errors

  • Help! Getting the cannot find symbol error.

    Hello everyone. I have gone throught my whole program and I am still getting a cannot find symbol error. What does this error mean exactly? Here is the code below. I am trying to color a background using a comobox method.
    import java.awt.BorderLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.ButtonGroup;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.border.EtchedBorder;
    import javax.swing.border.TitledBorder;
    import java.awt.GridLayout;
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import javax.swing.JComboBox;
    public class ComboboxFrame extends JFrame
        public ComboboxFrame()
            colorPanel = new JPanel();
            colorPanel.setPreferredSize(new Dimension(PANEL_WIDTH, PANEL_HEIGHT));
            getContentPane().add(colorPanel, BorderLayout.CENTER);
            class ChoiceListener implements ActionListener
                public void actionPerformed(ActionEvent event)
                    setbackgroundColor();
            listener = new ChoiceListener();
            createControlPanel();
            setbackgroundColor();
            pack();
        private void createControlPanel()
          JPanel colorPanel = createComboBox();
          JPanel controlPanel = new JPanel();
          controlPanel.setLayout(new GridLayout(1, 1));
          controlPanel.add(colorPanel);
          getContentPane().add(
             controlPanel, BorderLayout.SOUTH);
       public JPanel createComboBox()
          colorCombo = new JComboBox();
          colorCombo.addItem("Red");
          colorCombo.addItem("Green");
          colorCombo.addItem("Blue");
          colorCombo.setEditable(true);
          colorCombo.addActionListener(listener);
          JPanel panel = new JPanel();
          panel.add(colorCombo);
          return panel;
       public void setbackgroundColor()
           String color = (String)colorCombo.getSelectedItem();
           colorPanel.setbackgroundColor(new backgroungColor(color));
           colorPanel.repaint();
       private JPanel colorPanel; 
       private static final int PANEL_WIDTH = 300;
       private static final int PANEL_HEIGHT = 300;
       private JComboBox colorCombo;
       private ActionListener listener;
    }The line with the error is: colorPanel.setbackgroundColor(new backgroungColor(color));
    Here is the second file
    import javax.swing.JFrame;
    public class backgroundTest
        public static void main(String[] args)
            JFrame frame = new comboboxFrame();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.show();
    }Any help would be appreciated. Thank you

    Hello everyone. I have gone throught my whole
    program and I am still getting a cannot find symbol
    error. "Symbol" here means variable or method name (or maybe class name, but I think it will specifically bitch about classnames in that case).
    String foo = "foo";
    System.out.println(zoo); // no such variable as zoo. So...
    colorPanel.setbackgroundColor(new backgroungColor(color));Looks like colorPanel or setbackgroundColor(new backgroungColor doesn't exist.
    Note that spelling and capitalization count. Java's really anal that way.

  • Help - cannot find symbol error

    Can someone help me? I am getting "cannot find symbol" error in my code and cannot figure out why. Here is my code:
    public class toyInventory
    private String[] toyInventory = {"ball", "bat", "bear", "car", "doll", "game", "glove", "playstation", "train"};
    private int[] nineArray = {0,0,0,0,0,0,0,0};
    int invItems = 0;
    public void countToy()
    String orderInput[] = {"bear", "train", "car", "ball", "doll", "ball", "train", "doll", "game", "train", "bear", "doll", "train", "car", "ball", "bat", "glove", "bat", "b", "doll", "bear", "ball", "doll", "bat", "car", "glove", "train", "doll", "bear"};
    int noMatch;
    for(int a = 0; a < orderInput.length; a++)
    noMatch = 0;
    for(int b = 0; b < toyInventory.length; b++)
    if(orderInput[a] == toyInventory)
    noMatch = 1;
    break;
    if(noMatch == 0)
    invItems = 1;
    public void printItems()
    for(int c = 0; c < toyInventory.length; c++)
    if (countToy[c] > 4)<-------- cannot find symbol error here
    System.out.print("*");
    System.out.print(toyInventory[c] + "\t" + countToy[c] + "\n"); <----cannot find symbol error here also
    System.out.print("The number of invalid items in the order is" + invItems);
    public static void main( String[] args)
    toyInventory collection = new toyInventory ();
    collection.countToy();
    collection.printItems();

    public void countToy()
    String orderInput[] = {"bear", "train", "car", "ball", "doll", "ball", "train", "doll", "game", "train", "bear", "doll", "train", "car", "ball", "bat", "glove", "bat", "b", "doll", "bear", "ball", "doll", "bat", "car", "glove", "train", "doll", "bear"};In the above code you have declared countToy() as method and while in the below lines you are calling countToy[] as an array. So please check that...
    if (countToy[c] > 4)<-------- cannot find symbol error here
    System.out.print("*");
    System.out.print(toyInventory[c] + "\t" + countToy[c] + "\n"); <----cannot find symbol error here also
    }

  • Cannot find symbol error. don't know why

    Hello, I'm trying to write a button bean in the shape of a triangle but netbeans keeps throwing up a cannot find symbol error at my g.fillPolygon line. I've declared the number of sides and x and y coords.
    Any ideas as to why this is happening would be greatly appreciated.
    Here's the code:
    package trianglebutton;
    import java.util.*;
    import java.awt.event.*;
    import java.awt.*;
    import javax.swing.*;
    import java.io.*;
    public class TriangleButtonBean extends JButton implements Serializable
    private TriangleButtonBean graphicPolygon;
    private Color buttonColour;
    private Color textColour;
    private String caption;
    private int sides = 3;
    private int size = 30;
    private int centerX = 100;
    private int centerY = 100;
         public TriangleButtonBean()
              super();
              setPreferredSize(new Dimension(50,50));
              setBorder(null);
              buttonColour = Color.red;
              textColour = Color.black;
              caption = "";
         public TriangleButtonBean(String acaption)
              super();
              setPreferredSize(new Dimension(50,50));
              setBorder(null);
              caption = acaption;
         public void paintComponent(Graphics g)
    String astring;
              super.paintComponent(g);
    g.setColor(buttonColour);
              int centerX = graphicPolygon.getCenterX(); //Invoking getCenterX method
              int centerY = graphicPolygon.getCenterY(); //Invoking getCenterY method
              //int Xcoordinates [] = graphicPolygon.getPolygonXCoordinates(sides,size);
              //int Ycoordinates [] = graphicPolygon.getPolygonYCoordinates(sides,size);
    g.drawPolygon(centerX,centerY, sides); //Draw polygon using xcoord,ycoord and number of sides
              g.fillPolygon(centerX,centerY, sides); //Fill poly
              g.setColor(textColour);
              if (caption.length() > 1)
                   astring = caption.substring(0,1);
              else
                   astring = caption;
              g.drawString(astring,22,27);
         public void setButtonColour(Color acolour)
              buttonColour = acolour;
              repaint();
         public Color getButtonColour()
              return buttonColour;
         public void setTextColour(Color acolour)
              textColour = acolour;
              repaint();
         public Color getTextColour()
              return textColour;
         public void setCaption(String acaption)
              caption = acaption;
              repaint();
         public String getCaption()
              return caption;
    // public void setCenterX(int xcoords)
    // centerX = xcoords;
    public int getCenterX()
    return centerX;
    // public void setCenterY(int ycoords)
    // centerY = ycoords;
    public int getCenterY()
    return centerY;
    public static void main(String[] args){
    TriangleButtonBean agui = new TriangleButtonBean();
    } // End of class

    Please READ, STUDY, and UNDERSTAND the error messages, they are telling you exactly what the problem is:
    . . .\TriangleButtonBean.java:56: cannot find symbol
    symbol  : method drawPolygon(int,int,int)
    location: class java.awt.Graphics
    g.drawPolygon(centerX,centerY, sides); //Draw polygon using xcoord,ycoord and number of sides
    ^
    . . .\TriangleButtonBean.java:57: cannot find symbol
    symbol  : method fillPolygon(int,int,int)
    location: class java.awt.Graphics
    g.fillPolygon(centerX,centerY, sides); //Fill poly
    ^
    2 errors
    Process javac exited with code 1In both cases the messages ar telling you that the methods
    drawPolygon(int,int,int)
    method fillPolygon(int,int,int)
    can't be found in java.awt.Graphics
    And if you look at the documentation, you see that is indeed the problem - the first two arguments are int arrrays, not int.
    Fix the method signature or use something else.

  • Cannot find symbol error -- array fill from text file

    When I compile my program I receive a cannot find symbol error for the variable ayears. I thought this snippet would fill the array ayears that could be accessed later in the program but I am getting the error message from my buildGUI() class. What could I have done wrong?
    (my file options.txt contains data separated by a comma and a space)
    public void getOption(){
         InputStream istream;
         File options = new File("options.txt");
         istream = new FileInputStream(options);
         try {
                               StringBuffer sbuff = new StringBuffer();
                               BufferedReader inbuff = new
    BufferedReader(new FileReader(options));
                               String line = "";
                               while((line = inbuff.readLine()) != null) {
                               System.out.println(line); 
              sbuff.append(line);
                               inbuff.close();
                              String fileData = sbuff.toString();
              String[] splitData = fileData.split(", ");
              String[] ayears = new String[splitData.length];
         catch(Exception e){
         JOptionPane.showMessageDialog(null,
         "Could not find specified file", "Error Message",
         JOptionPane.ERROR_MESSAGE);
    }

    Okay -- that helped. I've avoided that error -- now on to the next one, why won't my array fill? It's going to be a long night.
    Thanks for the help.

  • "Cannot find Symbol" error message

    I have a "cannot find symbol" error message on line 5 below in
    the driver class.
    Thank you for your assistance
    1 public class GameLauncher
    2 {
    3  public static void main(String[] args)
    4 {
    5   GuessGame game = new GuessGame();
    6   game.startGame();
    7 }
    8}
    public class GuessGame
      public void startGame()
      Player p1;
      Player p2;
      Player p3;
      int guessp1 = 0;
      int guessp2 = 0;
      int guessp3 = 0;
      boolean p1isRight = false;
      boolean p2isRight = false;
      boolean p3isRight = false;
      int targetNumber = (int) (Math.random() * 10);
      System.out.println(" I'm thinking of a number between 0 and 9....");
      while(true)
        p1.guess();
        p2.guess();
        p3.guess();
        guessp1 = p1.number;
        System.out.println("Player one guessed " + guessp1);
        guessp2 = p2.number;
        System.out.println("Player two guessed " + guessp2);
        guessp3 = p3.number;
        System.out.println("Player three guessed " + guessp3);
        if (guessp1 == targetNumber)
          p1isRight = true;
        if (guessp2 == targetNumber)
          p2isRight = true;
        if (guessp3 == targetNumber)
          p3isRight = true;
        if ( p1isRight || p2isRight || p3isRight)
          System.out.println("We have a winner ! ");
          System.out.println("Player one got it right? " + p1isRight);
          System.out.println("Player two got it right? " + p2isRight);
          System.out.println("Player three got it right? " + p3isRight);
          System.out.println("Game is over ! ");
          break; //game is over so break out of loop
        else
          //we must keep going because no one guessed the number !
          System.out.println(" Players will have to try again ! ");
        } // end of if/else
      } // end of loop
    } // end of startGame() method
    } //end of class
    public class Player
      int number = 0;   // the guess is stored here
      public void guess()
        System.out.println(" I'm guessing " + number);
    ---------------------------------------------------------------  

    Thank you . You were right . I didn't set up the classes correctly.
    I corrected a few other errors and the program runs ok !
    Below is the corrected code and the output
    public class GameLauncher
      public static void main(String[] args)
       GuessGame game = new GuessGame();
       game.startGame();
    /* One possible set of output is
    I'm thinking of a number between 0 and 3....
    I'm guessing 1
    I'm guessing 3
    I'm guessing 0
    Player one guessed 1
    Player two guessed 3
    Player three guessed 0
    We have a winner !
    Player one got it right? true
    Player two got it right? false
    Player three got it right? false
    Game is over !
    public class Player
      int number = 0;   // the guess is stored here
      public void guess()
        number = (int)(Math.random() * 4);
        System.out.println(" I'm guessing " + number);
    public class GuessGame
      public void startGame()
        int x = 0;
      Player p1 = new Player();
      Player p2 = new Player();
      Player p3 = new Player();
      int guessp1 = 0;
      int guessp2 = 0;
      int guessp3 = 0;
      boolean p1isRight = false;
      boolean p2isRight = false;
      boolean p3isRight = false;
      int targetNumber = (int) (Math.random() * 4);
      System.out.println("\n I'm thinking of a number between 0 and 3....\n");
      while(x <5)
        p1.guess();
        p2.guess();
        p3.guess();
        guessp1 = p1.number;
        System.out.println("\nPlayer one guessed " + guessp1);
        guessp2 = p2.number;
        System.out.println("Player two guessed " + guessp2);
        guessp3 = p3.number;
        System.out.println("Player three guessed " + guessp3);
        if (guessp1 == targetNumber)
          p1isRight = true;
        if (guessp2 == targetNumber)
          p2isRight = true;
        if (guessp3 == targetNumber)
          p3isRight = true;
        if ( p1isRight || p2isRight || p3isRight)
          System.out.println("\nWe have a winner ! ");
          System.out.println("Player one got it right? " + p1isRight);
          System.out.println("Player two got it right? " + p2isRight);
          System.out.println("Player three got it right? " + p3isRight);
          System.out.println("Game is over ! ");
          break; //game is over so break out of loop
        else
          //we must keep going because no one guessed the number !
          System.out.println(" Players will have to try again ! ");
        } // end of if/else
        x = x + 1;
      } // end of loop
    } // end of startGame() method
    } //end of class 

  • Please help with cannot find symbol error. Been struggling all day :(

    Hi all. :)
    Writing a game for my phone with KToolbar and have been getting a cannot find symbol error for every variable and method I try to use across Classes. I've looked all over and though it seems a common problem I always either don't understand or can't get working the various solutions. Example of my errors:
    C:\...\BTK800i.java:197: cannot find symbol
    symbol : variable youSayWhat
    location: class HelloCanvas
              youSayWhat=key;
              ^
    If I try BTK800i.variable or BTK800i.message I get a new error.
    C:\...\src\BTK800i.java:184: non-static method newOrdersSarge() cannot be referenced from a static context
              BTK800i.newOrdersSarge();
              ^
    Both these errors apply to both variables and methods. It only happens when I'm using methods/variables of one class in another, am I using public and private incorrectly? It doesn't seem to make a difference if I make variables public or leave them private, I'm trying to get to them with a public method within a private class. Is it something else? I really have no idea. :(
    Here's my code, it's long enough to be a tiresome read so I've tried to skip what I know isn't relevant.
    public class BTK800i extends MIDlet {
         private Display myDisplay;
         private HelloCanvas myCanvas;
         public int youSayWhat;
            //a whole bunch more skipped here, but I'm fairly certain it's not anything that'll help find a solution
         public BTK800i() {
              paused=false;
    public void startApp() throws MIDletStateChangeException {
              if( paused ) {
                   myCanvas.repaint();
              else {
                   myDisplay=Display.getDisplay(this);
                   myCanvas=new HelloCanvas();
                   myDisplay.setCurrent(myCanvas);
                   myCanvas.setFullScreenMode(true);
                   youSayWhat=0;
                           //again with the skipping, more code not related
    public void newOrdersSarge() {
    //whole bunch of code
    //other methods skipped
    class HelloCanvas extends Canvas {
         public void keyPressed (int key) {
              youSayWhat=key;
              repaint ();
    //skippage
    }The stuff I skipped is mainly either more of the same sorta thing or maths/writing to screen stuff.
    Thanks alot to anyone who helps. I'm really struggling with this. :(
    Dan.

    But I have been reading them :(
    My next-door neighbour unfortunately is an 80-something married man, but I will go have a looksie about static and instances.
    I thought the point of public variables was that other classes could use them, is this wrong?
    Also does this mean that to use the variables from my BTK class in the HelloCanvas class I need to first instantiate BTK? I don't understand how that works as the code starts running from the BTK class in the first place :S I guess more reading will help with this.
    Thanks very much for replying. :)
    Edit:
    OK I have read up on it but I don't think I found anything I hadn't read before. I tried to make a new class which I could instantiate to hold all the variables and methods I wanted everything to be able to access, but that went disastrously. Am I right in understanding that there are no global variables in Java? :s
    Edited by: Dan69 on Apr 17, 2010 1:15 PM

  • Unable to compile "SerialDemo.java", many "cannot find symbols" errors

    I have all the correct files in their respective directory.
    comm.jar in jre\lib\bin,
    javax.comm.properties in jre\lib
    win32com.dll in jre\bin
    I extracted all the whole of SerialDemo into one folder and started compiling from there. But it doesn't work. I keep getting many "cannot find symbol" errors. They are usually referred to by:
    SerialParameters
    SerialConnection
    AlertDialog
    SerialConnectionException
    SerialDemo.java is not edited and was compiled directly. All of my files are in one folder (AlertDialog.java compiles fine and is in the same folder, etc)
    I was wondering what might be the cause of it. I'm currently using a Windows XP Service Pack 2, IBM P3 Laptop. I was reading "http://forum.java.sun.com/thread.jspa?threadID=674514&messageID=3941560"
    And I found out it works fine on Win2k OS. Why is this so? I'm getting the exact same error as he stated on his last post and I tried looking for a solution and decided to turn to you guys. I'd really appreciate some help, if any. Thanks in advance.

    I followed the PlatformSpecific. I realised that I
    added one for JRE when it wasn't required. The
    problem was solved.
    Thank you so much, the both of you. My stupid mistake
    caused quite a bit of havoc. I apologise.No need to apologise; The confusing part is that when you download
    a jre, that's just what your get: a jre, but when you download the jdk
    you not just get the jdk and the jre but you get a second jre with them,
    stored under the jdk directory.
    To the programmer that second jre is useless, it is used internally by
    the jdk tools.
    kind regards,
    Jos

  • "cannot find symbol" error - password checker class

    I had to make a program to check a password to make sure it had two letters, at least eight characters, and only numbers and letters. I'm pretty sure I have all of the checking correct but I can't make use of the method I made to do it. here is my code:
              if(password.LegalPassword())     
                   System.out.println("You enterend a valid password!");
              else
                   System.out.println("You have entered an invalid password!");
    class LegitPassword
                   //constructor
         public LegitPassword(String userPassword)
         public boolean LegalPassword (String userPassword)
                   int digitCounter = 0;
                   for(int i = 0; i < userPassword.length(); i++)
                             //is character a letter or number?
                        if(!(Character.isDigit(userPassword.charAt(i))) || !(Character.isLetter(userPassword.charAt(i))))
                             return false;
                             //is the password at least 8 characters?
                        if(userPassword.length() <= 8)
                             return false;
                             //count the digits
                        if(Character.isDigit(userPassword.charAt(i)))
                             digitCounter ++;
                   if(digitCounter <= 2)
                             return false;
         return true;
              }oh, and the exact error is:
    PasswordChecker.java:27: cannot find symbol
    symbol  : method LegalPassword()
    location: class java.lang.String
              if(password.LegalPassword())     
                         ^

    Here is the full code so that you can see how I declared password...
         public class PasswordChecker
              static Scanner console = new Scanner(System.in);
              public static void main(String[] args)
              String password;
              System.out.println("Please enter a new password.");
              System.out.println("Remember: Passwords must be at least eight characters"
                   + " consisting of only numbers and letters with at minimal two numbers.");
              System.out.print("Password: ");
                   password = console.nextLine();
              //LegitPassword thePassword = new LegitPassword(password);
              if(password.LegalPassword())     
                   System.out.println("You enterend a valid password!");
              else
                   System.out.println("You have entered an invalid password!");
    class LegitPassword
         public boolean LegalPassword (String userPassword)
                   int digitCounter = 0;
                   for(int i = 0; i < userPassword.length(); i++)
                             //is character a letter or number?
                        if(!(Character.isDigit(userPassword.charAt(i))) || !(Character.isLetter(userPassword.charAt(i))))
                             return false;
                             //is the password at least 8 characters?
                        if(userPassword.length() <= 8)
                             return false;
                             //count the digits
                        if(Character.isDigit(userPassword.charAt(i)))
                             digitCounter ++;
                   if(digitCounter <= 2)
                             return false;
         return true;
    }The error:
    PasswordChecker.java:27: cannot find symbol
    symbol  : method LegalPassword()
    location: class java.lang.String
              if(password.LegalPassword())Are you suggesting I change the method, LegalPassword, to accept no parameters?

  • Cannot find symbol ERROR

    cannot find symbolhi guys ... i getting this error... dunno what i did worng...
    i have two classes :
    package modaprend.Disciplines;
    public class LearningObjects {
    /** Creates a new instance of LearningObjects */
    public LearningObjects(String newPath){
    this.path = newPath;
    and :
    package modaprend.Disciplines;
    public class Exercises extends LearningObjects{
    /** Creates a new instance of Exercises */
    public Exercises() { ----> i got the error here
    ERROR :
    init:
    deps-jar:
    Compiling 1 source file to /home/pluster/Ual/LPP1/ModAprend/build/classes
    /home/pluster/Ual/LPP1/ModAprend/src/modaprend/Disciplines/Exercises.java:14: cannot find symbol
    symbol : constructor LearningObjects()
    location: class modaprend.Disciplines.LearningObjects
    public Exercises() {
    1 error
    BUILD FAILED (total time: 1 second)
    i running Linux (FC3) + JDK 5.0 + Netbeans 4.0 Beta 2 for editing
    Thanks

    It looks like LearningObjects has a single constructor that takes a String as an argument. That means the the ONLY way to create a LearningObjects object is with a String argument.
    Next, Excercises extends LearningObjects. Extends means "is a." So to create an Excercises object, an Excercises constructor MUST call a LearningObject constructor. If the only LearningObjects constructor requires a Sring, then the Excercises constructor MUST provide a String.
    You need to have a line like super("default"); as the first line in the Excercises constructor(s).

  • Another cannot find symbol error (DiveLog)

    Hi I am fairly new to java and I decided to try the tutorial DiveLog. I followed the instructions, however when I try to compile it, not with the DOS command, I keep getting an error stating that, Cannot find symbol class ..... The errors keep recurring at the tabbedPane.addTab(".....",
    package DiveLog;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class DiveLog
    { // Opens class
    public JTabbedPane tabbedPane;
    public JFrame dlframe;
    public DiveLog()
    { // Opens contructor
    //Create a frame object to add the application
    //GUI components to.
    dlframe = new JFrame("A Java(TM) Technology Dive Log");
    // Closes from title bar
    //and from menu
    dlframe.addWindowListener(new WindowAdapter()
    { // Opens addWindowListener method
    public void windowClosing(WindowEvent e)
    { // Opens windowClosing method
    System.exit(0);
    } // Closes windowClosing method
    }); // Closes addWindowListener method
    // Tabbed pane with panels for Jcomponents
    tabbedPane = new JTabbedPane(SwingConstants.LEFT);
    tabbedPane.setBackground(Color.blue);
    tabbedPane.setForeground(Color.white);
    //A method that adds individual tabs to the
    //tabbedpane object.
    populateTabbedPane();
    //Calls the method that builds the menu
    buildMenu();
    dlframe.getContentPane().add(tabbedPane);
    dlframe.pack();
    dlframe.setSize(765, 690);
    dlframe.setBackground(Color.white);
    dlframe.setVisible(true);
    } //Ends the constructor
    private void populateTabbedPane()
    { // Opens populateTabbedPane method
    // Create tabs with titles
    tabbedPane.addTab("Welcome",
    *               null,*
    *               new Welcome(),*
    *               "Welcome to the Dive Log");*
    *     tabbedPane.addTab("Diver Data",*
    *               null,*
    *               new Diver(),*
    *               "Click here to enter diver data");*
    *     tabbedPane.addTab("Log Dives",*
    *               null,*
    *               new Dives(),*
    *               "Click here to enter dives");*
    *     tabbedPane.addTab("Statistics",*
    *               null,*
    *               new Statistics(),*
    *               "Click here to calculate dive statistics");*
    *     tabbedPane.addTab("Favorite Web Site",*
    *               null,*
    *               new WebSite(),*
    *               "Click here to see a web site");*
    *     tabbedPane.addTab("Resources",*
    *               null,*
    *               new Resources(),*
    *               "Click here to see a list of resources");*
    *          } //Ends populateTabbedPane method*
    private void buildMenu()
    { // Opens buildMenu method
    JMenuBar mb = new JMenuBar();
    JMenu menu = new JMenu("File");
    JMenuItem item = new JMenuItem("Exit");
    //Closes the application from the Exit
    //menu item.
    item.addActionListener(new ActionListener()
    { // Opens addActionListener method
    public void actionPerformed(ActionEvent e)
    { // Opens actionPerformed method
    System.exit(0);
    } // Closes actionPerformed method
    }); // Closes addActionListener method
    menu.add(item);
    mb.add(menu);
    dlframe.setJMenuBar(mb);
    } //Ends the buildMenu method
    } //Ends class
    If you could help me, please explain it into terms that I would understand as I am still new to the entire language. Thanks

    cannot find symbol: whatever class or method signature or variable you use was never declared. It's as simple as that. Make sure that the names are correct; if a class is missing (thanks a bunch for omitting the relevant part of the error message :p), ensure the compiled .class file is in the classpath, if a method isn't found make sure that the arguments are provided exactly in the same order, number and type as the method declaration declares, and if a variable is missing make sure that you actually declared it.
    Learn about code tags when posting code next time, by the way.

  • Help a Beginner? cannot find symbol error?

    class Box {
         double width;
         double height;
         double depth;
    Box(Box ob) {
              width = ob.width;
              height = ob.height;
              depth = ob.depth;
    Box(double w, double h, double d) {
         width = w;
         height = h;
         depth = d;
    double volume() {
         return width * height * depth;
    class BoxWeight extends Box {
         double weight;
         BoxWeight(double w, double h, double d, double m) {
              width = w;
              height = h;
              depth = d;
              weight = m;
    class DemoBoxWeight {
         public static void main(String[] args) {
              BoxWeight mybox1 = new BoxWeight(10, 20, 35, 34);
              double vol;
              vol = mybox1.volume();
              System.out.println("Weight of mybox1 is " + mybox1.weight);
    okay, this is basically from a book, but when I compile it in TextPad, it reads
    C:\Documents and Settings\Guest 1\Desktop\EPGY C015\Box\Box.java:27: cannot find symbol
    symbol : constructor Box()
    location: class Box
         BoxWeight(double w, double h, double d, double m) {
         ^
    1 error
    Tool completed with exit code 1
    Why is that and how can I fix it? :P

    Whenever you extend a class (here you're extending Box with BoxWeight), and create the subclass's constructor, the parent class's (or super class's) constructor gets called first whether it is explicitly called or not. So here in the BoxWeight constructor, the Box constructor is implicitly called:
    BoxWeight(double w, double h, double d, double m) {
      // even though you don't specify it, the Box() constructor is called here. 
      // it's as if you have here the call:
      super();
      width = w;
      height = h;
      depth = d;
      weight = m;
    }If you don't specify the super(), it get's implicitly called as the first call in the BoxWeight constructor. Notice that the implicit constructor has no parameters. Since Box does not have a constructor without parameters, this will throw an error. To get around this, you should explicitly call the super constructor with its proper parameters as the first method called in your BoxWeight constructor:
    BoxWeight(double w, double h, double d, double m) {
      super(w, h, d);  // *** here ***
      width = w;
      height = h;
      depth = d;
      weight = m;
    }

  • Please help. Cannot find symbol Error!

    I have been working on this code for days now. It keeps coming up with errors. The error says cannot find symbol. I will bold the areas that say that. I got it down to 23 from 42 but now I have no idea what the problem is. any help is greatly appreciated!! I only added a couple of them mainly because it is overwhelming. I can add the rest of someone replies. Thank you again. Oh and the Classpath is set right. I am compiling from the desktop where I have the file also. That was the first thing I checked after reading other threads related to this issue. :O)
    import javax.swing.*;
    import java.awt.event.*;
    public class InventoryPart4 extends JFrame
         private JTextArea text;
         private Inventory inv;
         private int view;
         public InventoryPart4() {
              super("Product");
              setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // quit if the window is closed
              view = 0; // current one showing
              Product product;
              inv = new Inventory(4);
              product = new Product(1, "Salad", 3, 4.95); here
              inv.add(product, 0);
    product = new Product(2, "Dressing", 6, 3.00); here          
    inv.add(product, 1);
    product = new Product(3, "Bacon Bits", 2, 1.75);*here*
              inv.add(product, 2);
    product = new Product(4, "Croutons", 1, 1.75); here
              inv.add(product, 3);
              // sort
              inv.sort();
              // output
              for (int i = 0; i < 4; i++) {
                   System.out.println(inv.get(i));
              // total val
              System.out.printf("Total=$%.2f", inv.totalValue());
              //gui
              JPanel panel = new JPanel();
              panel.setLayout(new BoxLayout(panel,BoxLayout.Y_AXIS));
              text = new JTextArea(10,50);
              text.setEditable(false);
              panel.add(text);
              showProduct();
              JButton next = new JButton("Next");
    here          next.addProduct(new Product() {
                   public void actionPerformed(ActionEvent e) {
                        if (view < inv.size()-1) view++;
                        else view = 0;
                        showProduct();
              panel.add(next);
              getContentPane().add(panel);
         // view an item
         public void showProduct() {
              text.setText("Product Details:\n");
              text.append(inv.get(view).toString()+"\n");
              text.append(String.format
                        ("Value of all the Contents: $%.2f", inv.totalValue()));
         public static void main(String args [])
              InventoryPart4 invt = new InventoryPart4();
              invt.pack();
              invt.setVisible(true);
         } //end main
    } // end class InventoryPart1
    class Product {
    private int ProductItem;
    private int ProductStock;
    private double ProductPrice;
    public Product(int item, int stock, double price) {
    ProductItem = item;
    ProductStock = stock;
    ProductPrice = price;
    } //end three-argument constructor
    // set Product Item
    public void setProductItem(int item) {
    ProductItem = item; here
    } //end method set Product Item
    //return Product Item
    public int getsProductItem() {
    return productItem;
    } //end method get product Item
    //set Product Stock
    public void setProductStock(int stock) {
    productStock = stock;
    } //end method set Product Stock
    //return Product Stock
    public int getProductStock() {
    return productStock;
    } //end method get Product Stock
    public void setProductPrice(double price) {
    productPrice = price;
    } //end method setproductPrice
    //return Product Price
    public double getProductPrice() {
    return ProductPrice;
    } //end method get Product Price
    //calculate inventory value
    public double value() {
    return productPrice * productStock;
    }// end method get productPrice and productStock
    @Override
    public String toString() {
    return String.format("item=%3d units=%d price=%.2f value=%.2f",
    productItem, productStock, productPrice, value());
    }//end class Product
    class Inventory {
         private Product[] list;
         // constructor
         public Inventory(int size) {
              list = new Product[size];
         // complete value
         public double totalValue() {
              double val = 0.0;
              for (int i = 0; i < list.length; i++) {
                   val += list.value();
              return val;
         // add an item
         public void add(Product i, int p) {
              list[p] = i;
         // get an item
         public Product get(int i) {
              return list[i];
         // sort by name
         public void sort() {
              // bubble sort
              int n = list.length;
              for (int search = 1; search < n; search++) {
                   for (int i = 0; i < n-search; i++) {
                        if (list[i].getProductItem().compareToIgnoreCase(list[i+1].getProductItem()) > 0) {
                             // swap
                             Product temp = list[i];
                             list[i] = list[i+1];
                             list[i+1] = temp;
         public int size() {
              return list.length;
    //extended class
    class Contents extends Product {
         private String Contents;
         // constructor
         public Contents(int item, String name, int units, double price) {
              super(item,name,units, price);
              this.contents = contents;
         // getter
         public String getContents() {
              return Contents;
         // total value with the 5% fee
         public double value() {
              return super.value()*1.05;
         // just the 5% fee
         public double fee() {
              return super.value()*0.05;
         // setter
         public void setContents(String contents) {
              this.contents = contents;
         public String toString()
              return super.toString() + String.format(" fee=%.2f contents=%-20s",
                        fee(), contents);

    The error says cannot find symbol.It says more than that. It says what symbol it cannot find, and it points to the line of code where the symbol was used.
              product = new Product(1, "Salad", 3, 4.95); *here*So it can't find a class called Product with an accessible constructor Product(int, String, int, double).
    product = new Product(2, "Dressing", 6, 3.00); *here*          
    inv.add(product, 1);
    product = new Product(3, "Bacon Bits", 2, 1.75);*here*
              inv.add(product, 2);
    product = new Product(4, "Croutons", 1, 1.75); *here*
              inv.add(product, 3);Ditto.
              JButton next = new JButton("Next");
    *here*          next.addProduct(new Product() {JButton doesn't have an addProduct() method.
    public Product(int item, int stock, double price) {This constructor doesn't match the constructor you are calling above, and there are no other constructors.
    ProductItem = item; *here*You must have a typo. But don't use inital capitals on field names: use them only on class names.
    return productItem;Here is evidence that you have a typo. Java is case-sensitive. Either the field is caled 'ProductItem' or it is called 'productItem', not both.
              // bubble sortDo you have to do this for the homework? Bubble sort is never used in real code except by people who don't know what they're talking about. Use Collections.sort().
              super(item,name,units, price);You should be getting a compile error here too. Ther is no such constructor for Product.
              return Contents;And here.

Maybe you are looking for