Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-30-2009, 11:17 PM
Member
 
Join Date: Apr 2009
Location: I live Stafford Texas right outside of Houston.
Posts: 78
Rep Power: 0
tlouvierre is on a distinguished road
Default E:\IT 215 Java Programming\GUI1.java:125: class, interface, or enum expected
Code:
public class GUI1 extends JFrame implements ActionListener { 

     private JTextArea output; 
     private int current = 0; 
     private Inventory inv; 
     private JButton next; 

     public GUI1() { 
          super("Product GUI"); 
          setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // end the program when we are done 

          // number of products... 
          int number = Integer.parseInt(JOptionPane.showInputDialog("Please tell me the number of products to enter")); 

          // Set up the inventory 
          inv = new Inventory(number); 

          // enter the product info using a series of dialogs 
          for (int i = 0; i < number; i++) { 
               int item = Integer.parseInt(JOptionPane.showInputDialog("Enter the item's number")); 

               String name = JOptionPane.showInputDialog("Enter the item's name"); 

               int units = Integer.parseInt(JOptionPane.showInputDialog("Enter the units in stock")); 

               double price = Double.parseDouble(JOptionPane.showInputDialog("Enter the price of each item")); 

               String title = JOptionPane.showInputDialog("Enter the title"); 

               // make the object 
               CD p = new CD(item, name, units, price, title); 

               // put it in the inventory 
               inv.add(i,p); 
          } 

          // Sort the inv 
          inv.sort(); 

          // now popup the "real" gui for the display of the products... 
          JPanel content = new JPanel(); 
          setContentPane(content); 

          content.setLayout(new BoxLayout(content,BoxLayout.Y_AXIS)); 

          output = new JTextArea(20,50); 
          output.setEditable(false); 
          content.add(output); 

          next = new JButton("Next"); 
          next.setActionCommand("Next"); 
          next.addActionListener(this); 
          content.add(next); 

          if (inv.size() > 0) 
               display(inv.get(0)); 
          else { 
               next.setText("End"); 
               next.setEnabled(false); 
          } 
          if (current == inv.size()-1) { 
               next.setText("End"); 
               next.setEnabled(false); 
          } 

     } 

     // button pushes... 
     public void actionPerformed(ActionEvent evt) { 
          if (evt.getActionCommand().equals("Next")) { 
               if (current < inv.size()-1) { 
                    current++; 
                    CD p = inv.get(current); 
                    display(p); 
               } 
               if (current == inv.size()-1) { 
                    next.setText("End"); 
                    next.setEnabled(false); 
               } 
          } 
     } 

     // show a record 
     public void display(CD p) { 
          String str = ""; 
          str += "Item number: " + p.getItem() + "\n"; 
          str += "Item name: " + p.getName() + "\n"; 
          str += "Items in stock: " + p.getUnits() + "\n"; 
          str += "Price: $" + p.getPrice() + "\n"; 
          str += "Fee: $" + (p.value() - p.value()/1.05) + "\n"; 
          str += "Value (including the fee): $" + p.value() + "\n"; 

          // total value of it 
          str += "Total fee: $" + (inv.totalValue() - inv.totalValue()/1.05) + "\n"; 
          str += "Total value (including the fee): $" + inv.totalValue() + "\n"; 
          output.setText(str); 
     } 

     public static void main(String args[]) { 
          // setup and display the gui 
          GUI1 g = new GUI1(); 
          g.pack(); 
          g.setVisible(true); 
     } 
} 
public class CD extends Product { 
      
     // title of the DVD 
     private String title; 
      
     // constructor 
     public CD(int item, String name, int units, double price, String title) { 
          super(item,name,units, price); 
          this.title = title; 
     } 
      
     public String getTitle() { 
          return title; 
     } 
      
     // total value with the 5% fee 
     public double value() { 
          return super.value()*1.05; 
     } 
}import java.util.*; 

public class Inventory { 
     // Stores multiple products... 
      
     private CD[] prods; // field 
      
     // Constructor, based on the size of the array we want 
     public Inventory(int size) { 
          prods = new CD[size]; 
     } 
      
     // Add a product 
     public void add(int loc, CD p) { 
          prods[loc] = p; 
     } 
      
     // getter for a product 
     public CD get(int loc) { 
          return prods[loc]; 
     } 
      
     // sort the array! 
     public void sort() { 
          Arrays.sort(prods); 
     } 
      
     public int size() { 
          return prods.length; 
     } 
      
     // Total the value of all the products 
     public double totalValue() { 
          double val = 0.0; 
          for (int i = 0; i < prods.length; i++) { 
               val += prods.value(); 
          } 
          return val; 
     } 
} 
// Stores a Product 
public class Product implements Comparable { 

     // fields 
     private int item; 
     private String name; 
     private int units; 
     private double price; 
      
     // constructor 
     public Product(int item, String name, int units, double price) { 
          this.item = item; 
          this.name = name; 
          this.units = units; 
          this.price = price; 
     } 
      
     // total value 
     public double value() { 
          return units*price; 
     } 
      
     // getters and setters 

     public int getItem() { 
          return item; 
     } 

     public void setItem(int item) { 
          this.item = item; 
     } 

     public String getName() { 
          return name; 
     } 

     public void setName(String name) { 
          this.name = name; 
     } 

     public int getUnits() { 
          return units; 
     } 

     public void setUnits(int units) { 
          this.units = units; 
     } 

     public double getPrice() { 
          return price; 
     } 

     public void setPrice(double price) { 
          this.price = price; 
     } 
      
     // for the sorting 
     public int compareTo(Object p) { 
          final Product o = (Product)p; // make it a product 
          return (this.getName().compareToIgnoreCase(o.getName())); // compare the names 
     } 
      
}
I have tried moving import to the beginning of the line but nothing happened. It just says illegal start up.
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 05-31-2009, 03:17 PM
Fubarable's Avatar
Moderator
 
Join Date: Jun 2008
Posts: 6,506
Rep Power: 8
Fubarable is on a distinguished road
Default
Again, are you different Java classes in different files or are they all in the same file? (as was already mentioned to you several times in this thread: E:\IT 215 Java Programming\Inventory.java:36: class, interface, or enum expected)

Best of luck.

Last edited by Fubarable; 05-31-2009 at 03:23 PM.
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
E:\IT 215 Java Programming\Inventory.java:36: class, interface, or enum expected tlouvierre Advanced Java 16 05-28-2009 04:41 PM
E:\IT 215 Java Programming\public class Inventory.java:39: class, interface, or enum tlouvierre New To Java 14 05-28-2009 06:44 AM
'class' or 'interface' expected denisdoherty New To Java 23 04-22-2008 07:13 PM
class or interface expected -compile err ravi503 Java Servlet 1 03-26-2008 12:45 PM
illegal start of expression & class, interface, or enum expected silverq_82 New To Java 9 08-08-2007 08:16 PM


All times are GMT +2. The time now is 04:29 PM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org