Results 1 to 2 of 2
- 05-30-2009, 11:17 PM #1
Member
- Join Date
- Apr 2009
- Location
- I live Stafford Texas right outside of Houston.
- Posts
- 78
- Rep Power
- 0
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 } }
-
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: http://www.java-forums.org/advanced-...-expected.html)
Best of luck.Last edited by Fubarable; 05-31-2009 at 03:23 PM.
Similar Threads
-
E:\IT 215 Java Programming\Inventory.java:36: class, interface, or enum expected
By tlouvierre in forum Advanced JavaReplies: 16Last Post: 05-28-2009, 04:41 PM -
E:\IT 215 Java Programming\public class Inventory.java:39: class, interface, or enum
By tlouvierre in forum New To JavaReplies: 14Last Post: 05-28-2009, 06:44 AM -
'class' or 'interface' expected
By denisdoherty in forum New To JavaReplies: 23Last Post: 04-22-2008, 07:13 PM -
class or interface expected -compile err
By ravi503 in forum Java ServletReplies: 1Last Post: 03-26-2008, 12:45 PM -
illegal start of expression & class, interface, or enum expected
By silverq_82 in forum New To JavaReplies: 9Last Post: 08-08-2007, 08:16 PM
Bookmarks