Results 1 to 3 of 3
  1. #1
    ambria1975 is offline Member
    Join Date
    Jun 2010
    Posts
    11
    Rep Power
    0

    Default I need help with an error! Cannot find symbol error!

    I keep getting an error saying cannot find symbol. I checked the classpath and it is set the right way. I have been working on this code for days now and I cannot find out what the problem is. Can anyone help me figure this out? I will highlight the areas where the problem is in bold.

    Java Code:
    import javax.swing.*;
    Java Code:
     
    [FONT=Times New Roman][SIZE=3]import java.awt.event.*;[/SIZE][/FONT]
     
    [FONT=Times New Roman][SIZE=3]public class InventoryPart4 extends JFrame[/SIZE][/FONT]
    [FONT=Times New Roman][SIZE=3]{[/SIZE][/FONT]
     
    [SIZE=3][FONT=Times New Roman]           private JTextArea text;[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]           private Inventory inv;[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]           private int view;[/FONT][/SIZE]
     
    [SIZE=3][FONT=Times New Roman]           public InventoryPart4() {[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]                       super("Product");[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]                       setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // quit if the window is closed[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]                       view = 0; // current one showing[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]                       //[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]                       Product product;[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]                       inv = new Inventory(4);[/FONT][/SIZE]
     
    [SIZE=3][FONT=Times New Roman]                       [B]product = new Product(1, "Salad", 3, 4.95);[/B][/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]                       inv.add(product, 0);[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]       [B]product = new Product(2, "Dressing", 6, 3.00);[/B][/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]                       inv.add(product, 1);[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]       [B]product = new Product(3, "Bacon Bits", 2, 1.75);[/B][/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]                       inv.add(product, 2);[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]       [B]product = new Product(4, "Croutons", 1, 1.75);[/B][/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]                       inv.add(product, 3);[/FONT][/SIZE]
     
    [SIZE=3][FONT=Times New Roman]                       // sort[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]                       inv.sort();[/FONT][/SIZE]
     
    [SIZE=3][FONT=Times New Roman]                       // output[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]                       for (int i = 0; i < 4; i++) {[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]                                   System.out.println(inv.get(i));[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]                       }[/FONT][/SIZE]
     
    [SIZE=3][FONT=Times New Roman]                       // total val[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]                       System.out.printf("Total=$%.2f", inv.totalValue());[/FONT][/SIZE]
     
     
    [SIZE=3][FONT=Times New Roman]                       //gui[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]                       JPanel panel = new JPanel();[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]                       panel.setLayout(new BoxLayout(panel,BoxLayout.Y_AXIS));[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]                       text = new JTextArea(10,50);[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]                       text.setEditable(false);[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]                       panel.add(text);[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]                       showProduct();[/FONT][/SIZE]
     
    [SIZE=3][FONT=Times New Roman]                       JButton next = new JButton("Next");[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]                       [B]next.addProduct(new Product() {[/B][/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]                                   public void actionPerformed(ActionEvent e) {[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]                                               if (view < inv.size()-1) view++;[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]                                               else view = 0;[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]                                               showProduct();[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]                                   }[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]                       });[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]                       panel.add(next);[/FONT][/SIZE]
     
     
    [SIZE=3][FONT=Times New Roman]                       getContentPane().add(panel);[/FONT][/SIZE]
     
    [SIZE=3][FONT=Times New Roman]           }[/FONT][/SIZE]
     
    [SIZE=3][FONT=Times New Roman]           // view an item[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]           public void showProduct() {[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]                       text.setText("Product Details:\n");[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]                       text.append(inv.get(view).toString()+"\n");[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]                       text.append(String.format[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]                                               ("Value of all the Contents: $%.2f", inv.totalValue()));[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]           }[/FONT][/SIZE]
     
    [SIZE=3][FONT=Times New Roman]           public static void main(String args [])[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]           {[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]                       InventoryPart4 invt = new InventoryPart4();[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]                       invt.pack();[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]                       invt.setVisible(true);[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]           } //end main[/FONT][/SIZE]
     
    [FONT=Times New Roman][SIZE=3]} // end class InventoryPart1[/SIZE][/FONT]
     
     
    [FONT=Times New Roman][SIZE=3]class Product {[/SIZE][/FONT]
     
    [SIZE=3][FONT=Times New Roman]   private int ProductItem;[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]   private int ProductStock;[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]   private double ProductPrice;[/FONT][/SIZE]
     
    [SIZE=3][FONT=Times New Roman]   public Product(int item, int stock, double price) {[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]       ProductItem = item;[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]       ProductStock = stock;[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]       ProductPrice = price;[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]   } //end three-argument constructor[/FONT][/SIZE]
     
    [SIZE=3][FONT=Times New Roman]   // set Product Item[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]   public void setProductItem(int item) {[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]       ProductItem = item;[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]   } //end method  set Product Item[/FONT][/SIZE]
     
    [SIZE=3][FONT=Times New Roman]   //return Product Item[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]   public int getsProductItem() {[/FONT][/SIZE]
    [B][SIZE=3][FONT=Times New Roman]       return productItem;[/FONT][/SIZE][/B]
    [SIZE=3][FONT=Times New Roman]   } //end method get product Item[/FONT][/SIZE]
     
    [SIZE=3][FONT=Times New Roman]   //set Product Stock[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]   public void setProductStock(int stock) {[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]       [B]productStock = stock;[/B][/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]   } //end method set Product Stock[/FONT][/SIZE]
     
    [SIZE=3][FONT=Times New Roman]   //return Product Stock[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]   public int getProductStock() {[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]       [B]return productStock;[/B][/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]   } //end method get Product Stock[/FONT][/SIZE]
     
    [SIZE=3][FONT=Times New Roman]   public void setProductPrice(double price) {[/FONT][/SIZE]
    [B][SIZE=3][FONT=Times New Roman]       productPrice = price;[/FONT][/SIZE][/B]
    [SIZE=3][FONT=Times New Roman]   } //end method setproductPrice[/FONT][/SIZE]
     
    [SIZE=3][FONT=Times New Roman]   //return Product Price[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]   public double getProductPrice() {[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]       return ProductPrice;[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]   } //end  method get Product Price[/FONT][/SIZE]
     
    [SIZE=3][FONT=Times New Roman]   //calculate inventory value[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]   public double value() {[/FONT][/SIZE]
    [B][SIZE=3][FONT=Times New Roman]       return productPrice * productStock;[/FONT][/SIZE][/B]
    [SIZE=3][FONT=Times New Roman]   }// end method get productPrice and productStock[/FONT][/SIZE]
     
    [SIZE=3][FONT=Times New Roman]   @Override[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]   public String toString() {[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]       return String.format("item=%3d   units=%d   price=%.2f   value=%.2f",[/FONT][/SIZE]
    [B][SIZE=3][FONT=Times New Roman]               productItem, productStock, productPrice, value());[/FONT][/SIZE][/B]
    [SIZE=3][FONT=Times New Roman]   }[/FONT][/SIZE]
    [FONT=Times New Roman][SIZE=3]}//end class Product[/SIZE][/FONT]
     
     
     
    [FONT=Times New Roman][SIZE=3]class Inventory {[/SIZE][/FONT]
     
    [SIZE=3][FONT=Times New Roman]           private Product[] list;[/FONT][/SIZE]
     
    [SIZE=3][FONT=Times New Roman]           // constructor[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]           public Inventory(int size) {[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]                       list = new Product[size];[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]           }[/FONT][/SIZE]
     
    [SIZE=3][FONT=Times New Roman]           // complete value[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]           public double totalValue() {[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]                       double val = 0.0;[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]                       for (int i = 0; i < list.length; i++) {[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]                                   val += list[i].value();[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]                       }[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]                       return val;[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]           }[/FONT][/SIZE]
     
    [SIZE=3][FONT=Times New Roman]           // add an item[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]           public void add(Product i, int p) {[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]                       list[p] = i;[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]           }[/FONT][/SIZE]
     
    [SIZE=3][FONT=Times New Roman]           // get an item[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]           public Product get(int i) {[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]                       return list[i];[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]           }[/FONT][/SIZE]
     
    [SIZE=3][FONT=Times New Roman]           // sort by name[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]           public void sort() {[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]                       // bubble sort[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]                       int n = list.length;[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]                       for (int search = 1; search < n; search++) {[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]                                   for (int i = 0; i < n-search; i++) {[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]                                               [B]if (list[i].getProductItem().compareToIgnoreCase(list[i+1].getProductItem()) > 0) {[/B][/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]                                                           // swap[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]                                                           Product temp = list[i];[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]                                                           list[i] = list[i+1];[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]                                                           list[i+1] = temp;[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]                                               }[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]                                   }[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]                       }[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]           }[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]           public int size() {[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]                       return list.length;[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]           }[/FONT][/SIZE]
    [FONT=Times New Roman][SIZE=3]}[/SIZE][/FONT]
     
     
     
    [FONT=Times New Roman][SIZE=3]//extended class[/SIZE][/FONT]
    [FONT=Times New Roman][SIZE=3]class Contents extends Product {[/SIZE][/FONT]
     
    [SIZE=3][FONT=Times New Roman]           // [/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]           private String Contents;[/FONT][/SIZE]
     
    [SIZE=3][FONT=Times New Roman]           // constructor[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]           public Contents(int item, String name, int units, double price) {[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]                       [B]super(item,name,units, price);[/B][/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]                       [B]this.contents = contents;[/B][/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]           }[/FONT][/SIZE]
     
    [SIZE=3][FONT=Times New Roman]           // getter[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]           public String getContents() {[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]                       return Contents;[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]           }[/FONT][/SIZE]
     
    [SIZE=3][FONT=Times New Roman]           // total value with the 5% fee[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]           public double value() {[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]                       return super.value()*1.05;[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]           }[/FONT][/SIZE]
     
    [SIZE=3][FONT=Times New Roman]           // just the 5% fee[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]           public double fee() {[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]                       return super.value()*0.05;[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]           }[/FONT][/SIZE]
     
    [SIZE=3][FONT=Times New Roman]           // setter[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]           public void setContents(String contents) {[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]                       [B]this.contents = contents;[/B][/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]           }[/FONT][/SIZE]
     
    [SIZE=3][FONT=Times New Roman]           public String toString()[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]           {[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]                       return super.toString() + String.format("   fee=%.2f   contents=%-20s",[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]                                               fee(), contents);[/FONT][/SIZE]
    [SIZE=3][FONT=Times New Roman]           }[/FONT][/SIZE]
    [FONT=Times New Roman][SIZE=3]}[/SIZE][/FONT]

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Some recommendations, I'm sure others will give you more:

    --- deleted. cross-posted without notification --
    Last edited by Fubarable; 07-07-2010 at 01:38 AM.

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Please do not cross-post without notification. Post deleted.

    The problem is that you're asking unpaid volunteers to help you here, not paid consultants, and most of us mind if we take time away from work/lives/play to try to help someone only to find that we've provided a solution that was already provided in a cross-post hours ago. The proper thing to do is that if you feel you must cross-post, at least provide links in each cross-post to the other, so that folks don't waste time answering something already answered and so that folks can review all discussions that have already occurred.

Similar Threads

  1. Cannot find symbol error
    By rajivjoshi in forum New To Java
    Replies: 3
    Last Post: 05-31-2010, 10:13 AM
  2. error cannot find symbol
    By jcoon3 in forum New To Java
    Replies: 3
    Last Post: 09-27-2009, 10:56 PM
  3. Replies: 9
    Last Post: 10-18-2008, 08:26 PM
  4. 'Cannot find symbol' error
    By minihazard10 in forum New To Java
    Replies: 6
    Last Post: 10-10-2008, 04:05 AM
  5. Error: cannot find symbol
    By cachi in forum AWT / Swing
    Replies: 1
    Last Post: 08-06-2007, 08:12 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •