Results 1 to 2 of 2
  1. #1
    tlouvierre is offline Member
    Join Date
    Apr 2009
    Location
    I live Stafford Texas right outside of Houston.
    Posts
    78
    Rep Power
    0

    Default E:\IT 215 Java Programming\GUI1.java:125: class, interface, or enum expected

    Java 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 
         } 
          
    }

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

Similar Threads

  1. Replies: 1
    Last Post: 05-31-2009, 03:17 PM
  2. Replies: 16
    Last Post: 05-28-2009, 04:41 PM
  3. Replies: 14
    Last Post: 05-28-2009, 06:44 AM
  4. 'class' or 'interface' expected
    By denisdoherty in forum New To Java
    Replies: 23
    Last Post: 04-22-2008, 07:13 PM
  5. Replies: 9
    Last Post: 08-08-2007, 08:16 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
  •