| | |
Need help with JAVA Inventory program
![]() |
•
•
Join Date: May 2008
Posts: 2
Reputation:
Solved Threads: 0
I am receiving a successful build msg, but I cannot get my program to run correctly. Hereis the msg. followed by the program: Thanks in advance for any and all help.
Java Syntax (Toggle Plain Text)
init: deps-jar: compile: run: java.lang.NoClassDefFoundError: Inventory5_5 Caused by: java.lang.ClassNotFoundException: Inventory5_5 at java.net.URLClassLoader$1.run(URLClassLoader.java:200) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:188) at java.lang.ClassLoader.loadClass(ClassLoader.java:306) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276) at java.lang.ClassLoader.loadClass(ClassLoader.java:251) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319) Exception in thread "main" Java Result: 1 BUILD SUCCESSFUL (total time: 0 seconds)
Java Syntax (Toggle Plain Text)
package inventory4; import java.util.*; import javax.swing.*; import java.awt.event.*; import java.awt.*; class inventory4 extends JFrame { private class MyPanel extends JPanel { ImageIcon image = new ImageIcon("Sample.jpg"); int width = image.getIconWidth(); int height = image.getIconHeight(); long angle = 30; public MyPanel() { super(); } public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g; g2d.rotate(Math.toRadians(angle), 60 + width / 2, 60 + height / 2); g2d.drawImage(image.getImage(), 60, 60, this); g2d.dispose(); } }//end class MyPanel int currentIndex; //Currently displayed Item Product[] supplies = new Product[4]; JLabel name; JLabel number; JLabel title; JLabel quantity; JLabel price; JLabel fee; JLabel totalValue; JTextField nameField = new JTextField(20); JTextField numberField = new JTextField(20); JTextField titleField = new JTextField(20); JTextField quantityField = new JTextField(20); JTextField priceField = new JTextField(20); JPanel display; JPanel displayHolder; JPanel panel; public inventory4() { setSize(500, 500); setTitle("Bob's CD Inventory Program"); //make the panels display = new JPanel(); JPanel other = new JPanel(); JPanel picture = new MyPanel(); JPanel centerPanel = new JPanel(); displayHolder = new JPanel(); display.setLayout(new GridLayout(7, 1)); //other.setLayout(new GridLayout(1, 1)); //make the labels name = new JLabel("Name :"); number = new JLabel("Number :"); title = new JLabel("Title :"); quantity = new JLabel("Quantity :"); price = new JLabel("Price :"); fee = new JLabel("Restocking Fee :"); totalValue = new JLabel("Total Value :"); //Add the labels to the display panel display.add(name); display.add(number); display.add(title); display.add(quantity); display.add(price); display.add(fee); //Add the panels to the frame getContentPane().add(centerPanel, "Center"); getContentPane().add(other, "South"); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); } } class CD extends Product { String genre; double restockingFee; public CD(String genre, double restockingFee, int item, String title, double stockQuantity, double price) { //super(title,item, stockQuantity, price); this.genre = genre; this.restockingFee = restockingFee; // TODO Auto-generated constructor stub } //returns the value of the inventory, plus the restocking fee public double getInventoryValue() { // TODO Auto-generated method stub return super.getItemPrice() + restockingFee; } public String toString() { StringBuffer sb = new StringBuffer("Genre \t").append(genre).append("\n"); sb.append(super.toString()); return sb.toString(); } } //Inventory4.java class Product implements Comparable { private String title; // class variable that stores the item name private int item; // class variable that stores the item number private double stockQuantity; // class variable that stores the quantity in stock private double price; // class variable that stores the item price private String genre; public Product() { title = ""; item = 0; stockQuantity = 0; price = 0.0; genre = ""; } public Product(String title, String genre, int item, double stockQuantity, double price) { this.title = title; this.item = item; this.stockQuantity = stockQuantity; this.price = price; this.genre = genre; } public void setTitle(String title) { this.title = title; } public String getTitle() { return title; } public void setItem(int item) { this.item = item; } public int getItem() { return item; } public void setStockQuantity(double quantity) { stockQuantity = quantity; } public double getStockQuantity() { return stockQuantity; } public void setItemPrice(double price) { this.price = price; } public double getItemPrice() { return price; } public void setGenre(String genre) { this.genre = genre; } public String getGenre() { return genre; } public double calculateInventoryValue() { return price * stockQuantity; } public int compareTo(Object o) { Product p = null; try { p = (Product) o; } catch (ClassCastException cE) { cE.printStackTrace(); } return title.compareTo(p.getTitle()); } public String toString() { return "CD Title: " + title + "\nGenre: " + genre + "\nItem #: " + item + "\nPrice: $" + price + "\nQuantity: " + stockQuantity + "\nValue with restocking fee: $" + (calculateInventoryValue() + (calculateInventoryValue() * .05)); } } public class Inventory4 { Product[] supplies; public static void main(String[] args) { Inventory4 inventory = new Inventory4(); inventory.addProduct(new Product("Mozart", "Classical", 1, 54, 11.50)); inventory.addProduct(new Product("Beethoven", "Classical", 2, 65, 12.00)); inventory.addProduct(new Product("Tiny Tim", "Classical", 3, 10, 1.00)); System.out.println("Inventory of CD's:\n\n"); System.out.println(); inventory.showInventory(); System.out.println(); double total = inventory.calculateTotalInventory(); System.out.println("Total Value is: $" + (total + (total * .05))); } public void sortByName() { for (int i = 1; i < supplies.length; i++) { int j; Product val = supplies[i]; for (j = i - 1; j > -1; j--) { Product temp = supplies[j]; if (temp.compareTo(val) <= 0) { break; } supplies[j + 1] = temp; } supplies[j + 1] = val; } } //creates a String representation of the array of products public String toString() { String s = ""; for (Product p : supplies) { s = s + p.toString(); s = s + "\n\n"; } return s; } //Using an array so adding an item requires us to increase the size of the array first public void addProduct(Product p1) { if (supplies == null) { supplies = new Product[0]; } Product[] p = supplies; //Copy all products into p first Product[] temp = new Product[p.length + 1]; //create bigger array for (int i = 0; i < p.length; i++) { temp[i] = p[i]; } temp[(temp.length - 1)] = p1; //add the new product at the last position supplies = temp; } //sorting the array using Bubble Sort public double calculateTotalInventory() { double total = 0.0; for (int i = 0; i < supplies.length; i++) { total = total + supplies[i].calculateInventoryValue(); } return total; } public void showInventory() { System.out.println(toString()); //call our toString method } }
That will be because he is not following recommended naming standarts
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
•
•
Join Date: Jun 2008
Posts: 1
Reputation:
Solved Threads: 0
•
•
•
•
I am receiving a successful build msg, but I cannot get my program to run correctly. Hereis the msg. followed by the program:Java Syntax (Toggle Plain Text)
init: deps-jar: compile: run: java.lang.NoClassDefFoundError: Inventory5_5 Caused by: java.lang.ClassNotFoundException: Inventory5_5 at java.net.URLClassLoader$1.run(URLClassLoader.java:200) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:188) at java.lang.ClassLoader.loadClass(ClassLoader.java:306) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276) at java.lang.ClassLoader.loadClass(ClassLoader.java:251) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319) Exception in thread "main" Java Result: 1 BUILD SUCCESSFUL (total time: 0 seconds)Thanks in advance for any and all help.Java Syntax (Toggle Plain Text)
package inventory4; import java.util.*; import javax.swing.*; import java.awt.event.*; import java.awt.*; class inventory4 extends JFrame { private class MyPanel extends JPanel { ImageIcon image = new ImageIcon("Sample.jpg"); int width = image.getIconWidth(); int height = image.getIconHeight(); long angle = 30; public MyPanel() { super(); } public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g; g2d.rotate(Math.toRadians(angle), 60 + width / 2, 60 + height / 2); g2d.drawImage(image.getImage(), 60, 60, this); g2d.dispose(); } }//end class MyPanel int currentIndex; //Currently displayed Item Product[] supplies = new Product[4]; JLabel name; JLabel number; JLabel title; JLabel quantity; JLabel price; JLabel fee; JLabel totalValue; JTextField nameField = new JTextField(20); JTextField numberField = new JTextField(20); JTextField titleField = new JTextField(20); JTextField quantityField = new JTextField(20); JTextField priceField = new JTextField(20); JPanel display; JPanel displayHolder; JPanel panel; public inventory4() { setSize(500, 500); setTitle("Bob's CD Inventory Program"); //make the panels display = new JPanel(); JPanel other = new JPanel(); JPanel picture = new MyPanel(); JPanel centerPanel = new JPanel(); displayHolder = new JPanel(); display.setLayout(new GridLayout(7, 1)); //other.setLayout(new GridLayout(1, 1)); //make the labels name = new JLabel("Name :"); number = new JLabel("Number :"); title = new JLabel("Title :"); quantity = new JLabel("Quantity :"); price = new JLabel("Price :"); fee = new JLabel("Restocking Fee :"); totalValue = new JLabel("Total Value :"); //Add the labels to the display panel display.add(name); display.add(number); display.add(title); display.add(quantity); display.add(price); display.add(fee); //Add the panels to the frame getContentPane().add(centerPanel, "Center"); getContentPane().add(other, "South"); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); } } class CD extends Product { String genre; double restockingFee; public CD(String genre, double restockingFee, int item, String title, double stockQuantity, double price) { //super(title,item, stockQuantity, price); this.genre = genre; this.restockingFee = restockingFee; // TODO Auto-generated constructor stub } //returns the value of the inventory, plus the restocking fee public double getInventoryValue() { // TODO Auto-generated method stub return super.getItemPrice() + restockingFee; } public String toString() { StringBuffer sb = new StringBuffer("Genre \t").append(genre).append("\n"); sb.append(super.toString()); return sb.toString(); } } //Inventory4.java class Product implements Comparable { private String title; // class variable that stores the item name private int item; // class variable that stores the item number private double stockQuantity; // class variable that stores the quantity in stock private double price; // class variable that stores the item price private String genre; public Product() { title = ""; item = 0; stockQuantity = 0; price = 0.0; genre = ""; } public Product(String title, String genre, int item, double stockQuantity, double price) { this.title = title; this.item = item; this.stockQuantity = stockQuantity; this.price = price; this.genre = genre; } public void setTitle(String title) { this.title = title; } public String getTitle() { return title; } public void setItem(int item) { this.item = item; } public int getItem() { return item; } public void setStockQuantity(double quantity) { stockQuantity = quantity; } public double getStockQuantity() { return stockQuantity; } public void setItemPrice(double price) { this.price = price; } public double getItemPrice() { return price; } public void setGenre(String genre) { this.genre = genre; } public String getGenre() { return genre; } public double calculateInventoryValue() { return price * stockQuantity; } public int compareTo(Object o) { Product p = null; try { p = (Product) o; } catch (ClassCastException cE) { cE.printStackTrace(); } return title.compareTo(p.getTitle()); } public String toString() { return "CD Title: " + title + "\nGenre: " + genre + "\nItem #: " + item + "\nPrice: $" + price + "\nQuantity: " + stockQuantity + "\nValue with restocking fee: $" + (calculateInventoryValue() + (calculateInventoryValue() * .05)); } } public class Inventory4 { Product[] supplies; public static void main(String[] args) { Inventory4 inventory = new Inventory4(); inventory.addProduct(new Product("Mozart", "Classical", 1, 54, 11.50)); inventory.addProduct(new Product("Beethoven", "Classical", 2, 65, 12.00)); inventory.addProduct(new Product("Tiny Tim", "Classical", 3, 10, 1.00)); System.out.println("Inventory of CD's:\n\n"); System.out.println(); inventory.showInventory(); System.out.println(); double total = inventory.calculateTotalInventory(); System.out.println("Total Value is: $" + (total + (total * .05))); } public void sortByName() { for (int i = 1; i < supplies.length; i++) { int j; Product val = supplies[i]; for (j = i - 1; j > -1; j--) { Product temp = supplies[j]; if (temp.compareTo(val) <= 0) { break; } supplies[j + 1] = temp; } supplies[j + 1] = val; } } //creates a String representation of the array of products public String toString() { String s = ""; for (Product p : supplies) { s = s + p.toString(); s = s + "\n\n"; } return s; } //Using an array so adding an item requires us to increase the size of the array first public void addProduct(Product p1) { if (supplies == null) { supplies = new Product[0]; } Product[] p = supplies; //Copy all products into p first Product[] temp = new Product[p.length + 1]; //create bigger array for (int i = 0; i < p.length; i++) { temp[i] = p[i]; } temp[(temp.length - 1)] = p1; //add the new product at the last position supplies = temp; } //sorting the array using Bubble Sort public double calculateTotalInventory() { double total = 0.0; for (int i = 0; i < supplies.length; i++) { total = total + supplies[i].calculateInventoryValue(); } return total; } public void showInventory() { System.out.println(toString()); //call our toString method } }
Please follow the steps:
1. Compile the code as following
javac -d . Inventory4.java
2. Execute as following
java inventory4.Inventory4
![]() |
Similar Threads
- Inventory program part 5 help (Java)
- Inventory part 5 (Java)
Other Threads in the Java Forum
- Previous Thread: Front end using Applets
- Next Thread: Null Pointer Exception.......
| Thread Tools | Search this Thread |
-xlint add android api applet application applications array arrays automation bank bi binary blackberry bluetooth chat class client code compile compiler component database development digit eclipse equation error event fractal freeze functiontesting game gameprogramming givemetehcodez graphics gui health html hyper ide idea image infinite input int integer j2me java javame javaprojects jetbrains jni jpanel jtable julia learningresources linux list login loop main map method methods mobile myregfun netbeans newbie nonstatic notdisplaying pearl problem program programming project qt recursion scanner screen scrollbar server set sms sort sorting spamblocker sql sqlserver string superclass swing system text-file thread threads tree variablebinding windows xor






