Need help with JAVA Inventory program

Reply

Join Date: May 2008
Posts: 2
Reputation: bjeff71 is an unknown quantity at this point 
Solved Threads: 0
bjeff71 bjeff71 is offline Offline
Newbie Poster

Need help with JAVA Inventory program

 
0
  #1
May 31st, 2008
I am receiving a successful build msg, but I cannot get my program to run correctly. Hereis the msg. followed by the program:
  1. init:
  2. deps-jar:
  3. compile:
  4. run:
  5. java.lang.NoClassDefFoundError: Inventory5_5
  6. Caused by: java.lang.ClassNotFoundException: Inventory5_5
  7. at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
  8. at java.security.AccessController.doPrivileged(Native Method)
  9. at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
  10. at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
  11. at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
  12. at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
  13. at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
  14. Exception in thread "main"
  15. Java Result: 1
  16. BUILD SUCCESSFUL (total time: 0 seconds)
  1. package inventory4;
  2.  
  3. import java.util.*;
  4. import javax.swing.*;
  5. import java.awt.event.*;
  6. import java.awt.*;
  7.  
  8. class inventory4 extends JFrame {
  9.  
  10. private class MyPanel extends JPanel {
  11.  
  12. ImageIcon image = new ImageIcon("Sample.jpg");
  13. int width = image.getIconWidth();
  14. int height = image.getIconHeight();
  15. long angle = 30;
  16.  
  17. public MyPanel() {
  18. super();
  19. }
  20.  
  21. public void paintComponent(Graphics g) {
  22. super.paintComponent(g);
  23. Graphics2D g2d = (Graphics2D) g;
  24. g2d.rotate(Math.toRadians(angle), 60 + width / 2, 60 + height / 2);
  25. g2d.drawImage(image.getImage(), 60, 60, this);
  26. g2d.dispose();
  27. }
  28. }//end class MyPanel
  29. int currentIndex; //Currently displayed Item
  30. Product[] supplies = new Product[4];
  31. JLabel name;
  32. JLabel number;
  33. JLabel title;
  34. JLabel quantity;
  35. JLabel price;
  36. JLabel fee;
  37. JLabel totalValue;
  38. JTextField nameField = new JTextField(20);
  39. JTextField numberField = new JTextField(20);
  40. JTextField titleField = new JTextField(20);
  41. JTextField quantityField = new JTextField(20);
  42. JTextField priceField = new JTextField(20);
  43. JPanel display;
  44. JPanel displayHolder;
  45. JPanel panel;
  46.  
  47. public inventory4() {
  48.  
  49.  
  50. setSize(500, 500);
  51. setTitle("Bob's CD Inventory Program");
  52. //make the panels
  53. display = new JPanel();
  54. JPanel other = new JPanel();
  55. JPanel picture = new MyPanel();
  56. JPanel centerPanel = new JPanel();
  57. displayHolder = new JPanel();
  58. display.setLayout(new GridLayout(7, 1));
  59. //other.setLayout(new GridLayout(1, 1));
  60.  
  61. //make the labels
  62. name = new JLabel("Name :");
  63. number = new JLabel("Number :");
  64. title = new JLabel("Title :");
  65. quantity = new JLabel("Quantity :");
  66. price = new JLabel("Price :");
  67. fee = new JLabel("Restocking Fee :");
  68. totalValue = new JLabel("Total Value :");
  69.  
  70.  
  71. //Add the labels to the display panel
  72. display.add(name);
  73. display.add(number);
  74. display.add(title);
  75. display.add(quantity);
  76. display.add(price);
  77. display.add(fee);
  78.  
  79.  
  80. //Add the panels to the frame
  81.  
  82. getContentPane().add(centerPanel, "Center");
  83. getContentPane().add(other, "South");
  84. this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  85. setVisible(true);
  86. }
  87. }
  88.  
  89. class CD extends Product {
  90.  
  91. String genre;
  92. double restockingFee;
  93.  
  94. public CD(String genre, double restockingFee, int item, String title, double stockQuantity,
  95. double price) {
  96. //super(title,item, stockQuantity, price);
  97. this.genre = genre;
  98. this.restockingFee = restockingFee;
  99.  
  100. // TODO Auto-generated constructor stub
  101. }
  102.  
  103. //returns the value of the inventory, plus the restocking fee
  104. public double getInventoryValue() {
  105. // TODO Auto-generated method stub
  106. return super.getItemPrice() + restockingFee;
  107. }
  108.  
  109. public String toString() {
  110. StringBuffer sb = new StringBuffer("Genre \t").append(genre).append("\n");
  111. sb.append(super.toString());
  112.  
  113. return sb.toString();
  114. }
  115. }
  116.  
  117. //Inventory4.java
  118. class Product implements Comparable {
  119.  
  120. private String title; // class variable that stores the item name
  121. private int item; // class variable that stores the item number
  122. private double stockQuantity; // class variable that stores the quantity in stock
  123. private double price; // class variable that stores the item price
  124. private String genre;
  125.  
  126. public Product() {
  127. title = "";
  128. item = 0;
  129. stockQuantity = 0;
  130. price = 0.0;
  131. genre = "";
  132. }
  133.  
  134. public Product(String title, String genre, int item, double stockQuantity, double price) {
  135. this.title = title;
  136. this.item = item;
  137. this.stockQuantity = stockQuantity;
  138. this.price = price;
  139. this.genre = genre;
  140. }
  141.  
  142. public void setTitle(String title) {
  143. this.title = title;
  144. }
  145.  
  146. public String getTitle() {
  147. return title;
  148. }
  149.  
  150. public void setItem(int item) {
  151. this.item = item;
  152. }
  153.  
  154. public int getItem() {
  155. return item;
  156. }
  157.  
  158. public void setStockQuantity(double quantity) {
  159. stockQuantity = quantity;
  160. }
  161.  
  162. public double getStockQuantity() {
  163. return stockQuantity;
  164. }
  165.  
  166. public void setItemPrice(double price) {
  167. this.price = price;
  168. }
  169.  
  170. public double getItemPrice() {
  171. return price;
  172. }
  173.  
  174. public void setGenre(String genre) {
  175. this.genre = genre;
  176. }
  177.  
  178. public String getGenre() {
  179. return genre;
  180. }
  181.  
  182. public double calculateInventoryValue() {
  183. return price * stockQuantity;
  184. }
  185.  
  186. public int compareTo(Object o) {
  187. Product p = null;
  188. try {
  189. p = (Product) o;
  190. } catch (ClassCastException cE) {
  191. cE.printStackTrace();
  192. }
  193. return title.compareTo(p.getTitle());
  194. }
  195.  
  196. public String toString() {
  197. return "CD Title: " + title + "\nGenre: " + genre + "\nItem #: " + item + "\nPrice: $" + price + "\nQuantity: " + stockQuantity + "\nValue with restocking fee: $" + (calculateInventoryValue() + (calculateInventoryValue() * .05));
  198. }
  199. }
  200.  
  201. public class Inventory4 {
  202.  
  203. Product[] supplies;
  204.  
  205. public static void main(String[] args) {
  206. Inventory4 inventory = new Inventory4();
  207. inventory.addProduct(new Product("Mozart", "Classical", 1, 54, 11.50));
  208. inventory.addProduct(new Product("Beethoven", "Classical", 2, 65, 12.00));
  209. inventory.addProduct(new Product("Tiny Tim", "Classical", 3, 10, 1.00));
  210.  
  211. System.out.println("Inventory of CD's:\n\n");
  212.  
  213.  
  214. System.out.println();
  215. inventory.showInventory();
  216. System.out.println();
  217.  
  218. double total = inventory.calculateTotalInventory();
  219. System.out.println("Total Value is: $" + (total + (total * .05)));
  220.  
  221.  
  222. }
  223.  
  224. public void sortByName() {
  225. for (int i = 1; i < supplies.length; i++) {
  226. int j;
  227. Product val = supplies[i];
  228. for (j = i - 1; j > -1; j--) {
  229. Product temp = supplies[j];
  230. if (temp.compareTo(val) <= 0) {
  231. break;
  232. }
  233. supplies[j + 1] = temp;
  234. }
  235. supplies[j + 1] = val;
  236. }
  237. }
  238.  
  239. //creates a String representation of the array of products
  240. public String toString() {
  241. String s = "";
  242. for (Product p : supplies) {
  243. s = s + p.toString();
  244. s = s + "\n\n";
  245. }
  246. return s;
  247. }
  248.  
  249. //Using an array so adding an item requires us to increase the size of the array first
  250. public void addProduct(Product p1) {
  251. if (supplies == null) {
  252. supplies = new Product[0];
  253. }
  254. Product[] p = supplies; //Copy all products into p first
  255. Product[] temp = new Product[p.length + 1]; //create bigger array
  256. for (int i = 0; i < p.length; i++) {
  257. temp[i] = p[i];
  258. }
  259. temp[(temp.length - 1)] = p1; //add the new product at the last position
  260. supplies = temp;
  261. }
  262.  
  263. //sorting the array using Bubble Sort
  264. public double calculateTotalInventory() {
  265. double total = 0.0;
  266. for (int i = 0; i < supplies.length; i++) {
  267. total = total + supplies[i].calculateInventoryValue();
  268. }
  269. return total;
  270. }
  271.  
  272. public void showInventory() {
  273. System.out.println(toString()); //call our toString method
  274. }
  275. }
Thanks in advance for any and all help.
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: Need help with JAVA Inventory program

 
0
  #2
May 31st, 2008
it says it can't find a class with that name. That class doesn't exist.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 973
Reputation: Alex Edwards is a jewel in the rough Alex Edwards is a jewel in the rough Alex Edwards is a jewel in the rough Alex Edwards is a jewel in the rough 
Solved Threads: 107
Alex Edwards's Avatar
Alex Edwards Alex Edwards is offline Offline
Posting Shark

Re: Need help with JAVA Inventory program

 
0
  #3
Jun 3rd, 2008
I'm fairly confused as to why you use an inventory4 class than an Inventory4 class... It just adds to the confusion.

I'd also like to know how you got that compiler error. What line did you attempt to use Inventory5 (or Inventory5_5 ?)
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,191
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 485
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: Need help with JAVA Inventory program

 
0
  #4
Jun 3rd, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 1
Reputation: Manishbpl is an unknown quantity at this point 
Solved Threads: 0
Manishbpl Manishbpl is offline Offline
Newbie Poster

Re: Need help with JAVA Inventory program

 
0
  #5
Jun 3rd, 2008
Originally Posted by bjeff71 View Post
I am receiving a successful build msg, but I cannot get my program to run correctly. Hereis the msg. followed by the program:
  1. init:
  2. deps-jar:
  3. compile:
  4. run:
  5. java.lang.NoClassDefFoundError: Inventory5_5
  6. Caused by: java.lang.ClassNotFoundException: Inventory5_5
  7. at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
  8. at java.security.AccessController.doPrivileged(Native Method)
  9. at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
  10. at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
  11. at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
  12. at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
  13. at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
  14. Exception in thread "main"
  15. Java Result: 1
  16. BUILD SUCCESSFUL (total time: 0 seconds)
  1. package inventory4;
  2.  
  3. import java.util.*;
  4. import javax.swing.*;
  5. import java.awt.event.*;
  6. import java.awt.*;
  7.  
  8. class inventory4 extends JFrame {
  9.  
  10. private class MyPanel extends JPanel {
  11.  
  12. ImageIcon image = new ImageIcon("Sample.jpg");
  13. int width = image.getIconWidth();
  14. int height = image.getIconHeight();
  15. long angle = 30;
  16.  
  17. public MyPanel() {
  18. super();
  19. }
  20.  
  21. public void paintComponent(Graphics g) {
  22. super.paintComponent(g);
  23. Graphics2D g2d = (Graphics2D) g;
  24. g2d.rotate(Math.toRadians(angle), 60 + width / 2, 60 + height / 2);
  25. g2d.drawImage(image.getImage(), 60, 60, this);
  26. g2d.dispose();
  27. }
  28. }//end class MyPanel
  29. int currentIndex; //Currently displayed Item
  30. Product[] supplies = new Product[4];
  31. JLabel name;
  32. JLabel number;
  33. JLabel title;
  34. JLabel quantity;
  35. JLabel price;
  36. JLabel fee;
  37. JLabel totalValue;
  38. JTextField nameField = new JTextField(20);
  39. JTextField numberField = new JTextField(20);
  40. JTextField titleField = new JTextField(20);
  41. JTextField quantityField = new JTextField(20);
  42. JTextField priceField = new JTextField(20);
  43. JPanel display;
  44. JPanel displayHolder;
  45. JPanel panel;
  46.  
  47. public inventory4() {
  48.  
  49.  
  50. setSize(500, 500);
  51. setTitle("Bob's CD Inventory Program");
  52. //make the panels
  53. display = new JPanel();
  54. JPanel other = new JPanel();
  55. JPanel picture = new MyPanel();
  56. JPanel centerPanel = new JPanel();
  57. displayHolder = new JPanel();
  58. display.setLayout(new GridLayout(7, 1));
  59. //other.setLayout(new GridLayout(1, 1));
  60.  
  61. //make the labels
  62. name = new JLabel("Name :");
  63. number = new JLabel("Number :");
  64. title = new JLabel("Title :");
  65. quantity = new JLabel("Quantity :");
  66. price = new JLabel("Price :");
  67. fee = new JLabel("Restocking Fee :");
  68. totalValue = new JLabel("Total Value :");
  69.  
  70.  
  71. //Add the labels to the display panel
  72. display.add(name);
  73. display.add(number);
  74. display.add(title);
  75. display.add(quantity);
  76. display.add(price);
  77. display.add(fee);
  78.  
  79.  
  80. //Add the panels to the frame
  81.  
  82. getContentPane().add(centerPanel, "Center");
  83. getContentPane().add(other, "South");
  84. this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  85. setVisible(true);
  86. }
  87. }
  88.  
  89. class CD extends Product {
  90.  
  91. String genre;
  92. double restockingFee;
  93.  
  94. public CD(String genre, double restockingFee, int item, String title, double stockQuantity,
  95. double price) {
  96. //super(title,item, stockQuantity, price);
  97. this.genre = genre;
  98. this.restockingFee = restockingFee;
  99.  
  100. // TODO Auto-generated constructor stub
  101. }
  102.  
  103. //returns the value of the inventory, plus the restocking fee
  104. public double getInventoryValue() {
  105. // TODO Auto-generated method stub
  106. return super.getItemPrice() + restockingFee;
  107. }
  108.  
  109. public String toString() {
  110. StringBuffer sb = new StringBuffer("Genre \t").append(genre).append("\n");
  111. sb.append(super.toString());
  112.  
  113. return sb.toString();
  114. }
  115. }
  116.  
  117. //Inventory4.java
  118. class Product implements Comparable {
  119.  
  120. private String title; // class variable that stores the item name
  121. private int item; // class variable that stores the item number
  122. private double stockQuantity; // class variable that stores the quantity in stock
  123. private double price; // class variable that stores the item price
  124. private String genre;
  125.  
  126. public Product() {
  127. title = "";
  128. item = 0;
  129. stockQuantity = 0;
  130. price = 0.0;
  131. genre = "";
  132. }
  133.  
  134. public Product(String title, String genre, int item, double stockQuantity, double price) {
  135. this.title = title;
  136. this.item = item;
  137. this.stockQuantity = stockQuantity;
  138. this.price = price;
  139. this.genre = genre;
  140. }
  141.  
  142. public void setTitle(String title) {
  143. this.title = title;
  144. }
  145.  
  146. public String getTitle() {
  147. return title;
  148. }
  149.  
  150. public void setItem(int item) {
  151. this.item = item;
  152. }
  153.  
  154. public int getItem() {
  155. return item;
  156. }
  157.  
  158. public void setStockQuantity(double quantity) {
  159. stockQuantity = quantity;
  160. }
  161.  
  162. public double getStockQuantity() {
  163. return stockQuantity;
  164. }
  165.  
  166. public void setItemPrice(double price) {
  167. this.price = price;
  168. }
  169.  
  170. public double getItemPrice() {
  171. return price;
  172. }
  173.  
  174. public void setGenre(String genre) {
  175. this.genre = genre;
  176. }
  177.  
  178. public String getGenre() {
  179. return genre;
  180. }
  181.  
  182. public double calculateInventoryValue() {
  183. return price * stockQuantity;
  184. }
  185.  
  186. public int compareTo(Object o) {
  187. Product p = null;
  188. try {
  189. p = (Product) o;
  190. } catch (ClassCastException cE) {
  191. cE.printStackTrace();
  192. }
  193. return title.compareTo(p.getTitle());
  194. }
  195.  
  196. public String toString() {
  197. return "CD Title: " + title + "\nGenre: " + genre + "\nItem #: " + item + "\nPrice: $" + price + "\nQuantity: " + stockQuantity + "\nValue with restocking fee: $" + (calculateInventoryValue() + (calculateInventoryValue() * .05));
  198. }
  199. }
  200.  
  201. public class Inventory4 {
  202.  
  203. Product[] supplies;
  204.  
  205. public static void main(String[] args) {
  206. Inventory4 inventory = new Inventory4();
  207. inventory.addProduct(new Product("Mozart", "Classical", 1, 54, 11.50));
  208. inventory.addProduct(new Product("Beethoven", "Classical", 2, 65, 12.00));
  209. inventory.addProduct(new Product("Tiny Tim", "Classical", 3, 10, 1.00));
  210.  
  211. System.out.println("Inventory of CD's:\n\n");
  212.  
  213.  
  214. System.out.println();
  215. inventory.showInventory();
  216. System.out.println();
  217.  
  218. double total = inventory.calculateTotalInventory();
  219. System.out.println("Total Value is: $" + (total + (total * .05)));
  220.  
  221.  
  222. }
  223.  
  224. public void sortByName() {
  225. for (int i = 1; i < supplies.length; i++) {
  226. int j;
  227. Product val = supplies[i];
  228. for (j = i - 1; j > -1; j--) {
  229. Product temp = supplies[j];
  230. if (temp.compareTo(val) <= 0) {
  231. break;
  232. }
  233. supplies[j + 1] = temp;
  234. }
  235. supplies[j + 1] = val;
  236. }
  237. }
  238.  
  239. //creates a String representation of the array of products
  240. public String toString() {
  241. String s = "";
  242. for (Product p : supplies) {
  243. s = s + p.toString();
  244. s = s + "\n\n";
  245. }
  246. return s;
  247. }
  248.  
  249. //Using an array so adding an item requires us to increase the size of the array first
  250. public void addProduct(Product p1) {
  251. if (supplies == null) {
  252. supplies = new Product[0];
  253. }
  254. Product[] p = supplies; //Copy all products into p first
  255. Product[] temp = new Product[p.length + 1]; //create bigger array
  256. for (int i = 0; i < p.length; i++) {
  257. temp[i] = p[i];
  258. }
  259. temp[(temp.length - 1)] = p1; //add the new product at the last position
  260. supplies = temp;
  261. }
  262.  
  263. //sorting the array using Bubble Sort
  264. public double calculateTotalInventory() {
  265. double total = 0.0;
  266. for (int i = 0; i < supplies.length; i++) {
  267. total = total + supplies[i].calculateInventoryValue();
  268. }
  269. return total;
  270. }
  271.  
  272. public void showInventory() {
  273. System.out.println(toString()); //call our toString method
  274. }
  275. }
Thanks in advance for any and all help.
*****************************************************
Please follow the steps:
1. Compile the code as following
javac -d . Inventory4.java

2. Execute as following
java inventory4.Inventory4
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC