Inventory part 5

Reply

Join Date: Sep 2007
Posts: 3
Reputation: cmymazda is an unknown quantity at this point 
Solved Threads: 0
cmymazda cmymazda is offline Offline
Newbie Poster

Inventory part 5

 
0
  #1
Sep 28th, 2007
Hello everyone I am a new to java and I am trying to get help with my inventory program. Here is the assignment ..Modify the Inventory Program by adding a button to the GUI that allows the user to move
to the first item, the previous item, the next item, and the last item in the inventory. If the
first item is displayed and the user clicks on the Previous button, the last item should
display. If the last item is displayed and the user clicks on the Next button, the first item
should display.
• Add a company logo to the GUI using Java graphics classes. I am posting the code that I have so far from inventory 4 but i cant get it to compile and run and dont know where to start to complete this portion. Here is the code

  1.  
  2.  
  3. /******************************************************************
  4. * Modify the Inventory Program to use a GUI.
  5. * The GUI should display the information
  6. * one product at a time, including the item number,
  7. * the name of the product, the number of units in stock,
  8. * the price of each unit, and the value of the inventory
  9. * of that product. In addition, the GUI should display
  10. * the value of the entire inventory, the additional attribute,
  11. * and the restocking fee.
  12. *******************************************************************/
  13. // Inventory4 program for DVD
  14.  
  15.  
  16. import java.util.Arrays;
  17.  
  18.  
  19. public class Inventory4 {
  20.  
  21. public static void main(String[] args) {
  22. FeatDVD dvd= null;
  23. Inventory inventory = new Inventory();
  24.  
  25. dvd = new FeatDVD(0, "Bad Boys", 5, 12.99f, "Comedy");
  26. inventory.add(dvd);
  27.  
  28. dvd = new FeatDVD(1, "Color Purple", 7, 14.99f, "Drama");
  29. inventory.add(dvd);
  30.  
  31. dvd = new FeatDVD(2, "Madea Family Reunion", 6, 13.99f, "Drama");
  32. inventory.add(dvd);
  33.  
  34. dvd = new FeatDVD(3, "Diary of a Mad Black Woman", 3, 15.99f, "Drama");
  35. inventory.add(dvd);
  36.  
  37. dvd = new FeatDVD(4, "Forest Gump", 8, 11.99f, "Comedy");
  38. inventory.add(dvd);
  39.  
  40. dvd = new FeatDVD(5, "How Stella Got Her Groove Back", 2, 12.99f, "Drama");
  41. inventory.add(dvd);
  42.  
  43. dvd = new FeatDVD(6, "What's love Got to do With it", 7, 15.99f, "Drama");
  44. inventory.add(dvd);
  45.  
  46. dvd = new FeatDVD(7, "Purple Rain", 7, 11.99f, "Drama");
  47. inventory.add(dvd);
  48.  
  49. inventory.display();
  50.  
  51. GUI gui = new GUI(inventory); // Start the GUI
  52.  
  53.  
  54.  
  55.  
  56. } // end main
  57.  
  58. } // end class Inventory4
  59.  
  60. /**** Class decribes DVD while demostrating polymorphism and inheritance**/
  61.  
  62. class DVD implements Comparable
  63. {
  64.  
  65. private int dvditem;
  66. private String dvdtitle;
  67. private int dvdstock;
  68. private double dvdprice;
  69.  
  70.  
  71. // Constructor
  72. DVD()
  73. {
  74.  
  75. dvditem = 0;
  76. dvdtitle = "";
  77. dvdstock = 0;
  78. dvdprice = 0;
  79.  
  80. }// end constructor
  81.  
  82. //constructor initializes variables
  83. DVD(int item, String title, int stock, double price)
  84. {
  85.  
  86. this.dvditem = item;
  87. this.dvdtitle = title;
  88. this.dvdstock = stock;
  89. this.dvdprice = price;
  90. }
  91.  
  92. private void setTitle( String title )
  93. {
  94. this.dvdtitle = title;
  95. }
  96.  
  97. public String getdvdTitle()
  98. {
  99. return dvdtitle;
  100. }
  101.  
  102. private void setdvdItem( int item )
  103. {
  104. this.dvditem = item;
  105. }
  106.  
  107. public int getdvdItem()
  108. {
  109. return dvditem;
  110. }
  111.  
  112. private void setdvdStock( int stock )
  113. {
  114. this.dvdstock = stock;
  115. }
  116.  
  117. public int getdvdStock()
  118. {
  119. return dvdstock;
  120. }
  121.  
  122. private void setdvdPrice (double price )
  123. {
  124. this.dvdprice = price;
  125. }
  126.  
  127. public double getdvdPrice()
  128. {
  129. return dvdprice;
  130. }
  131.  
  132. public double getValue()
  133. {
  134. double value = dvdstock * dvdprice;
  135. return value;
  136. }
  137.  
  138. // This method tells the sort method what is to be sorted
  139. public int compareTo(Object o)
  140. {
  141. return dvdtitle.compareTo(((DVD) o).getdvdTitle());
  142. }
  143.  
  144. // This method passes the format for the string
  145. public String toString()
  146. {
  147. return String.format("Unit number:%d %12s Units:%2d Price: $%5.2f Movie value: $%6.2f",
  148. dvditem, dvdtitle, dvdstock, dvdprice, getValue());
  149. }
  150. } // end class DVD
  151.  
  152.  
  153. /**** This is a subclass that adds 5% restocking fee and new feature***/
  154.  
  155. class FeatDVD extends DVD
  156. {
  157. private String genres;
  158.  
  159. // class constructor
  160. FeatDVD(int item, String title, int stock, float price, String genres)
  161. {
  162. super(item, title, stock, price);
  163. this.genres = genres;
  164.  
  165. }
  166.  
  167. public double getValue()
  168. {// getvalue method overrides
  169. // getvalue method in the superclass
  170. double value = 1.05F * super.getValue();
  171. return value;
  172. }// end getValue method
  173.  
  174. public String toString()
  175. {//toString method overrides the superclass toString method
  176. //adding another fields
  177. return super.toString() + "Genre:" + genres;
  178. }// end toString method
  179.  
  180. }// end class FeatDVD
  181.  
  182. /*****class has inventory of DVDs.
  183. * This class has methods to add and display dvds****/
  184.  
  185.  
  186.  
  187. class Inventory
  188. {
  189. private DVD[] dvds;
  190. private int nCount;
  191.  
  192.  
  193. // constructor
  194. Inventory()
  195. {
  196. dvds = new DVD[10];
  197. nCount = 0;
  198. }
  199.  
  200. public void add(DVD dvd)
  201. {
  202. dvds[nCount] = dvd;
  203. ++nCount;
  204. sort();
  205. }
  206.  
  207.  
  208. public int getNcount()
  209. {
  210. return nCount;
  211. }
  212.  
  213. // method calculates total value of inventory
  214. public double getTotalValue()
  215. {
  216.  
  217. double totalValue = 0;
  218. for (int i = 0; i < nCount; i++)
  219. totalValue = dvds[i].getValue();
  220. return totalValue;
  221. } // end getTotalValue
  222.  
  223. public DVD getDVD(int n) //use in GUI
  224. {// protects n and keep in range
  225. if (n<0)
  226. n = 0;
  227. else if (n >= nCount)
  228. n = nCount - 1;
  229. return dvds[n];
  230. }
  231.  
  232.  
  233. // sorts the DVDs
  234. private void sort()
  235. {
  236. Arrays.sort(dvds, 0, nCount);
  237. }// end sort method
  238.  
  239. public void display()
  240. {
  241. System.out.println("\nThe inventory contains " + nCount + "DVDs\n");
  242. for (int i = 0; i < nCount; i++)
  243. System.out.printf("%d: %s\n", i, dvds[i]);
  244. System.out.printf("\nTotal value of the inventory is $%.2f\n", getTotalValue());
  245. } // end display method
  246.  
  247. } // end class Inventory

  1.  
  2. /*****************************************************
  3. * GUI.java is the graphical part of the program
  4. * for the Inventory part 4 program.
  5.  
  6. *****************************************************/
  7. //GUI.java
  8.  
  9. import java.awt.*;
  10. import java.awt.event.*;
  11. import javax.swing.*;
  12.  
  13.  
  14. // GUI class creates and maintains the GUI
  15. public class GUI extends JFrame
  16. {
  17. private Inventory inventory; // create new reference to object
  18. private JPanel jpOuterPanel; // for outermost frame
  19. private JPanel jpInstructsPanel; // the instructions
  20. private JPanel currentDataPanel; // the current data header
  21. private JLabel jlCurrentDataTitle; //the current data header
  22. private JLabel jlCurrentDataContents; // the data contents
  23. private JTextField jtfValue; // for data acquisition
  24. private JButton jbNext; // Next button
  25. private int nCurrentDVDnum; //selecting the current dvd
  26.  
  27. GUI(Inventory inventory)
  28. {
  29. super(" DVD Inventory Program");
  30. this.inventory = inventory;
  31. nCurrentDVDnum = 0;
  32.  
  33. // creates outer panel
  34. JPanel jp;
  35. jpOuterPanel = new JPanel();
  36. jpOuterPanel.setLayout(new BoxLayout(jpOuterPanel, BoxLayout.Y_AXIS));
  37.  
  38. // creates title line
  39. jpInstructsPanel = new JPanel();
  40. jpInstructsPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
  41. JLabel jLabel = new JLabel("Click on the 'Next DVD' button to see the next DVD");
  42. jpInstructsPanel.add(jLabel);
  43. jpOuterPanel.add(jpInstructsPanel);
  44.  
  45. // creates current data line
  46. jp = new JPanel();
  47. jp.setLayout(new FlowLayout(FlowLayout.CENTER));
  48. jlCurrentDataTitle = new JLabel("" + inventory.getDVD(nCurrentDVDnum));
  49. jp.add(jlCurrentDataTitle);
  50. jpOuterPanel.add(jp);
  51.  
  52. // creates the data contents display line
  53. jp = new JPanel();
  54. jp.setLayout(new FlowLayout(FlowLayout.CENTER));
  55. jlCurrentDataContents = new JLabel("This DVD collection contains " +
  56. inventory.getNcount() + " DVDs");
  57. jp.add(jlCurrentDataContents);
  58. jpOuterPanel.add(jp);
  59.  
  60. //create text field for data acquisition
  61. jp = new JPanel();
  62. jp.add(new JLabel("Value of DVD collection:"));
  63. jp.setLayout(new FlowLayout(FlowLayout.CENTER));
  64. jtfValue = new JTextField(4);
  65. jtfValue.setText("$" + inventory.getTotalValue());
  66. jtfValue.setEditable(false);
  67. jp.add(jtfValue);
  68. jpOuterPanel.add(jp);
  69.  
  70. updateFields(); // updates field after next button
  71.  
  72. // set up and add the next button
  73. jp = new JPanel();
  74. jp.setLayout(new FlowLayout(FlowLayout.CENTER));
  75. jbNext = new JButton("Next DVD");
  76. jbNext.addActionListener(new NextButtonHandler());
  77. jp.add(jbNext);
  78. jpOuterPanel.add(jp);
  79.  
  80. // quit application when window is closed
  81. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  82. setBounds(200, 200, 600, 300); // set frame location and size
  83.  
  84. // set up the outer panel, turn it on.
  85. setContentPane(jpOuterPanel);
  86. setResizable(false);
  87. setVisible(true);
  88.  
  89. } // end GUI constructor
  90.  
  91. private void updateFields() // updates info on the current DVD
  92. {
  93. jlCurrentDataTitle.setText((nCurrentDVDnum+1) + ": " + inventory.getDVD(nCurrentDVDnum));
  94. } // end updateFields method
  95.  
  96. // inner class to handle the next button
  97. class NextButtonHandler implements ActionListener
  98. {
  99. public void actionPerformed(ActionEvent event)
  100. { // sequences through the inventory
  101. ++nCurrentDVDnum;
  102. if (nCurrentDVDnum < inventory.getNcount())
  103. updateFields();
  104. else
  105. jbNext.setEnabled(false);
  106. } // end method
  107. }// end inner class
  108. }// end class GUI
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,355
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 500
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: Inventory part 5

 
0
  #2
Sep 28th, 2007
Post the errors that you are receiving and what problem you are having with it. You can't expect others to read the entire code line by line and debug it for you.
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,355
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 500
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: Inventory part 5

 
0
  #3
Sep 28th, 2007
Also, please use the search feature in this forum for "inventory program" and see what help you can gleam from those threads. We have helped a few people with this exact assignment series recently and there are many posts.
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,145
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: Inventory part 5

 
0
  #4
Sep 28th, 2007
we're not here to do your homework for you, and we're not going to go through hundreds of lines of code to find where your errors are located.

If you are getting compiler errors (which you should as you say it doesn't compile) solve those.
If you can't for whatever reason, post the error and relevant parts of the code only and maybe someone can help you.

Same with other problems, we're NOT going to do it all for you.
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: Jul 2007
Posts: 226
Reputation: no1zson is on a distinguished road 
Solved Threads: 1
no1zson's Avatar
no1zson no1zson is offline Offline
Posting Whiz in Training

Re: Inventory part 5

 
0
  #5
Oct 1st, 2007
I am one of the people helped through this recently.
Search on my name, there should be more than enough detail in those posts to answer any question for this assignment.
I am pretty sure I asked them all! :o)
I never drew first, but I drew first blood.
I'm no ones son, unforgiven.
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 3
Reputation: cmymazda is an unknown quantity at this point 
Solved Threads: 0
cmymazda cmymazda is offline Offline
Newbie Poster

Re: Inventory part 5

 
0
  #6
Oct 1st, 2007
Hello,

I will do that now and see what I can find. I have to get this one done before I can start on part 6.
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