Final- Inventory program part 6

Reply

Join Date: Jul 2008
Posts: 1
Reputation: javagreenhorn is an unknown quantity at this point 
Solved Threads: 0
javagreenhorn javagreenhorn is offline Offline
Newbie Poster

Final- Inventory program part 6

 
0
  #1
Jul 13th, 2008
Hello,

I have done the code for the final part of the Java Inventory Program in my class. This is the requirements for the final code.

• Modify the Inventory Program to include an Add button, a Delete button, and a Modify
button on the GUI. These buttons should allow the user to perform the corresponding
actions on the item name, the number of units in stock, and the price of each unit. An
item added to the inventory should have an item number one more than the previous last
item.
• Add a Save button to the GUI that saves the inventory to a C:\data\inventory.dat file.
• Use exception handling to create the directory and file if necessary.
• Add a search button to the GUI that allows the user to search for an item in the inventory
by the product name. If the product is not found, the GUI should display an appropriate
message. If the product is found, the GUI should display that product’s information in the
GUI.

Here is my code and following it are the errors I am getting. Any help would be greatly appreciated!

  1. tory Program
  2. * This program keeps track of products and calculates and displays;
  3. * price, name, number, quantity, and total inventory value.
  4. */
  5.  
  6. package stock;
  7.  
  8. /**IT 215
  9.  *June, 2008
  10.  * @author Tammy
  11.  */
  12.  
  13. import java.text.NumberFormat;
  14.  
  15.  
  16. public class Stock {
  17.  
  18. private String itemName;
  19. private int itemNumber;
  20. private int itemQuantity;
  21. private double itemPrice;
  22.  
  23.  
  24. public Stock () {
  25. this.itemName = "";
  26. this.itemNumber = 0;
  27. this.itemQuantity = 0;
  28. this.itemPrice = 0;
  29. }
  30.  
  31. public Stock(String name, int number, int quantity, double price) {
  32. this.itemName = name;
  33. this.itemNumber = number;
  34. this.itemQuantity = quantity;
  35. this.itemPrice = price;
  36. }
  37.  
  38. public void setItemName(String name) {
  39. this.itemName = name;
  40.  
  41. }
  42.  
  43. public void setItemPrice(double itemPrice) {
  44. this.itemPrice = itemPrice;
  45.  
  46. }
  47.  
  48. public void setItemQuantity(int quantity) {
  49. this.itemQuantity = quantity;
  50.  
  51. }
  52.  
  53. public void setItemNumber(int number) {
  54. this.itemNumber = number;
  55.  
  56. }
  57.  
  58. public String getItemName() {
  59. return this.itemName;
  60.  
  61. }
  62.  
  63. public int getItemNumber() {
  64. return this.itemNumber;
  65.  
  66. }
  67.  
  68. public double getItemPrice() {
  69. return this.itemPrice;
  70.  
  71. }
  72.  
  73. public int getItemQuantity() {
  74. return this.itemQuantity;
  75.  
  76. }
  77.  
  78. public double calculateTotalItemValue() {
  79. return getItemQuantity()* getItemPrice();
  80.  
  81. }
  82.  
  83. @Override
  84. public String toString() {
  85. NumberFormat currencyFormat = NumberFormat.getCurrencyInstance();
  86. return"\nItemName: "+getItemName() +"\nItem Number: "+getItemNumber()+"\nItemPrice:"
  87. +currencyFormat.format(getItemPrice())
  88. +"\nItem Quantity: " +getItemQuantity()
  89. +"\nValue of Inventory: " +currencyFormat.format(this.calculateTotalItemValue());
  90.  
  91. }
  92. }

  1. * To change this template, choose Tools | Templates
  2. * and open the template in the editor.
  3. */
  4.  
  5. package stock;
  6.  
  7. import java.text.NumberFormat;
  8.  
  9. /**
  10.  *
  11.  * @author Tammy
  12.  */
  13. public class StockSubClass extends Stock {
  14.  
  15. private String ItemGenre;
  16.  
  17. public StockSubClass() {
  18. super();
  19. ItemGenre = "";
  20.  
  21. }
  22.  
  23. public void setItemGenre (String genre) {
  24. this.ItemGenre = genre;
  25.  
  26. }
  27.  
  28. public String getItemGenre() {
  29. return this.ItemGenre;
  30.  
  31. }
  32.  
  33. //Total item inventory value
  34. public double calculateRestockFee() {
  35. return (super.getItemPrice() * .05);
  36.  
  37. }
  38.  
  39. //Total item inventory value
  40. public double calculateInventoryValue() {
  41. return (super.getItemPrice()*super.getItemQuantity() + calculateRestockFee());
  42. }
  43. //Total value of all inventory
  44. public static double getTotalInventoryValue(StockSubClass [] items) {
  45. double total = 0.0;
  46. for(int j = 0; j < items.length; j++) {
  47.  
  48. total += items[j].calculateInventoryValue();
  49.  
  50. }
  51. return total;
  52.  
  53. }
  54.  
  55. //Override toString function to display a single item
  56. @Override
  57. public String toString() {
  58. NumberFormat currencyFormat = NumberFormat.getCurrencyInstance();
  59.  
  60. return"\nItem Name: "+super.getItemName()+ "\nItem Number: "+super.getItemNumber()+"\nItem Price: "
  61. +currencyFormat.format(super.getItemPrice())+"\nRestock Fee: "
  62. +currencyFormat.format(calculateRestockFee())+"\nItem Quantity: "+super.getItemQuantity()+"\nGenre: "
  63. +getItemGenre()+"\nInventory Value: "+currencyFormat.format(this.calculateInventoryValue())+"\n\n";
  64.  
  65. }
  66.  
  67. }

  1.  
  2. * To change this template, choose Tools | Templates
  3. * and open the template in the editor.
  4. */
  5.  
  6. package stock;
  7.  
  8.  
  9. import java.util.*;
  10. import java.text.*;
  11.  
  12. /**
  13.  *
  14.  * @author Tammy
  15.  */
  16. public class StockInput {
  17.  
  18. private StockSubClass [] items;
  19.  
  20. //Constructor
  21. public StockInput (int numberOfitems)
  22. {
  23. items = new StockSubClass[numberOfitems];
  24. for (int i = 0; i < numberOfitems; i++) {
  25. items[i] = new StockSubClass();
  26. }
  27.  
  28. }
  29. public StockSubClass [] inputItems() {
  30.  
  31. items[0].setItemName("Hurricane Charley");
  32. items[0].setItemQuantity(3);
  33. items[0].setItemPrice(16.95);
  34. items[0].setItemNumber(152);
  35. items[0].setItemGenre("Documentary");
  36.  
  37.  
  38. items[1].setItemName("Eight Legged Freaks");
  39. items[1].setItemQuantity(7);
  40. items[1].setItemPrice(10.00);
  41. items[1].setItemNumber(342);
  42. items[1].setItemGenre("Horror");
  43.  
  44.  
  45. items[2].setItemName("Major Payne");
  46. items[2].setItemQuantity(3);
  47. items[2].setItemPrice(13.95);
  48. items[2].setItemNumber(294);
  49. items[2].setItemGenre("Comedy");
  50.  
  51.  
  52. items[3].setItemName("Phil the Alien");
  53. items[3].setItemQuantity(6);
  54. items[3].setItemPrice(7.95);
  55. items[3].setItemNumber(187);
  56. items[3].setItemGenre("Comedy");
  57.  
  58. return (items);
  59.  
  60. }
  61.  
  62. //Sort array by name
  63. public StockSubClass [] sortByItemName() {
  64. StockSubClass[] sorted = new StockSubClass[items.length];
  65. String [] names = new String[items.length];
  66.  
  67. for (int i =0; i < items.length; i++) {
  68. names[i] = items[i].getItemName();
  69. }
  70. Arrays.sort(names);
  71.  
  72. int index = -1;
  73. for (int i = 0; i < names.length; i++) {
  74. index = this.searchByName(names[i]);
  75. if (index != -1) {
  76. sorted[i] = items[index];
  77. }
  78.  
  79.  
  80. }
  81.  
  82. this.items = sorted;
  83. return (sorted);
  84.  
  85.  
  86. }
  87.  
  88.  
  89. private int searchByName(String name) {
  90. for(int i = 0; i < items.length; i++) {
  91. if (name.equals(items[i].getItemName())) {
  92. return i;
  93. }
  94. }
  95.  
  96. return -1;
  97.  
  98. }
  99. }

  1. * and open the template in the editor.
  2. */
  3.  
  4.  
  5. package stock;
  6.  
  7. /**
  8.  *
  9.  * @author Tammy
  10.  */
  11.  
  12.  
  13. import java.awt.BorderLayout;
  14. import java.awt.Component;
  15. import java.awt.Dimension;
  16. import java.awt.FlowLayout;
  17. import java.awt.event.ActionEvent;
  18. import java.math.BigDecimal;
  19. import javax.swing.JTextArea;
  20. import javax.swing.Icon;
  21. import javax.swing.ImageIcon;
  22. import javax.swing.SwingConstants;
  23. import javax.swing.JButton;
  24. import javax.swing.JFrame;
  25. import javax.swing.JLabel;
  26. import javax.swing.JOptionPane;
  27. import javax.swing.JPanel;
  28.  
  29.  
  30. public class StockGui extends JFrame {
  31.  
  32. private StockSubClass [] itemList;
  33. private StockInput myStock;
  34. public static final int MAXIMUM_ITEMS = 5;
  35. private JTextArea invTotal;
  36. private JLabel iconLabel;
  37. private JButton last;
  38.  
  39. public StockGui () {
  40. myStock = new StockInput(MAXIMUM_ITEMS);
  41. itemList = new StockSubClass[MAXIMUM_ITEMS];
  42. myStock.inputItems();
  43. itemList = myStock.sortByItemName();
  44.  
  45. }
  46.  
  47. private int position = 0;
  48. private int number = 0;
  49. public static final int width = 520;
  50. public static final int height = 460;
  51. public static final String TITLE = "Current Inventory";
  52. private JFrame jFrame = null;
  53. private JPanel jContentPane = null;
  54. private JPanel jPanel = null;
  55. private JLabel jLabel = null;
  56. private JButton next = null;
  57. private JButton previous = null;
  58. private JButton first = null;
  59.  
  60. //JLabels to display information
  61. private JLabel[] labels = new JLabel[10];
  62.  
  63. private void displayOneItem(StockSubClass stockSubClass) {
  64.  
  65. }
  66.  
  67. //Initialize JFrame
  68. private JFrame getJFrame() {
  69. if (jFrame == null) {
  70.  
  71. jFrame = new JFrame();
  72. jFrame.setContentPane(getJContentPane());
  73. jFrame.setSize(new Dimension(width, HEIGHT));
  74. jFrame.setTitle(TITLE);
  75. jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  76. jFrame.setVisible(true);
  77.  
  78. }
  79. return jFrame;
  80. }
  81.  
  82. //Initialize JContentPane
  83. private JPanel getJContentPane() {
  84. Object JContentPane = null;
  85. if (JContentPane == null) {
  86.  
  87. jContentPane = new JPanel();
  88. jContentPane.setLayout(new BorderLayout());
  89. jContentPane.add(getJPanel(), BorderLayout.CENTER);
  90. jContentPane.add(getJPanel1(), BorderLayout.SOUTH);
  91.  
  92. }
  93. return jContentPane;
  94. }
  95.  
  96. //Method initializes jPanel
  97. private JPanel getJPanel() {
  98. //Set up logo
  99. Icon logo = new ImageIcon(getClass().getResource("logo.jpg"));
  100. iconLabel = new JLabel(logo, SwingConstants.CENTER);
  101. iconLabel.setToolTipText("Company Logo");
  102. add(iconLabel);
  103.  
  104. if (jPanel == null) {
  105. jLabel = new JLabel();
  106. jLabel.setText("Current Inventory");
  107. jLabel.setHorizontalAlignment(SwingConstants.CENTER);
  108. jLabel.setPreferredSize(new Dimension(width, 30));
  109. jPanel = new JPanel();
  110. jPanel.setLayout(new FlowLayout());
  111. jPanel.add(jLabel);
  112. jPanel.add(getPanel("Item Number"));
  113. jPanel.add(getPanel("Item Name"));
  114. jPanel.add(getPanel("Item Quantity"));
  115. jPanel.add(getPanel("Item Price"));
  116. jPanel.add(getPanel("Inventory Value"));
  117. jPanel.add(getPanel("Restocking Fee"));
  118. jPanel.add(getPanel("Inventory Value w/ Restocking Fee"));
  119. jPanel.add(getPanel("Genre"));
  120. jPanel.add(getPanel("Total Value of All Inventory"));
  121.  
  122. displayOneItem(itemList[0]);
  123.  
  124. }
  125.  
  126. return jPanel;
  127.  
  128. }
  129.  
  130. public JPanel getPanel (String title) {
  131. JPanel panel = new JPanel();
  132. panel.setLayout(new FlowLayout());
  133. panel.setPreferredSize(new Dimension(width, 30));
  134. panel.add(getLabel(title, false));
  135. JLabel valueLabel = getLabel("", true);
  136. labels[number] = valueLabel;
  137. number++;
  138. panel.add(valueLabel);
  139. return panel;
  140.  
  141. }
  142.  
  143. public JLabel getLabel(String value, boolean end) {
  144. JLabel label = new JLabel();
  145.  
  146. if (!end) {
  147. label.setText(value +": ");
  148. label.setHorizontalAlignment(SwingConstants.TRAILING);
  149. label.setPreferredSize(new Dimension(width / 2, 20));
  150.  
  151. }
  152.  
  153. else {
  154. label.setText(value);
  155. label.setPreferredSize(new Dimension(width / 3, 20));
  156.  
  157. }
  158.  
  159. return label;
  160.  
  161. }
  162.  
  163. private Component getJPanel1() {
  164. throw new UnsupportedOperationException("Not yet implemented");
  165. }
  166.  
  167. //Initialize "Next" button
  168. private JButton getNext() {
  169. if(next == null) {
  170. next = new JButton("Next");
  171. next.addActionListener(new java.awt.event.ActionListener() {
  172.  
  173. public void actionPerformed(java.awt.event.ActionEvent e) {
  174.  
  175. next();
  176. }
  177.  
  178. });
  179. }
  180. return next;
  181. }
  182.  
  183.  
  184.  
  185. //Initialize "Previous" button
  186. private JButton getPrevious() {
  187. if (previous == null) {
  188. previous = new JButton("Previous");
  189. previous.addActionListener(new java.awt.event.ActionListener() {
  190.  
  191.  
  192.  
  193. public void actionPerformed(java.awt.event.ActionEvent e) {
  194. previous();
  195.  
  196. }
  197. });
  198. }
  199. return previous;
  200. }
  201.  
  202.  
  203.  
  204. //Initialize "First" button
  205. private JButton getFirst() {
  206. if(first == null) {
  207. first = new JButton("First");
  208. first.addActionListener(new java.awt.event.ActionListener() {
  209.  
  210. public void actionPerformed(java.awt.event.ActionEvent e) {
  211. first();
  212.  
  213. }
  214.  
  215. private void first() {
  216. StockSubClass itemCurrent = new StockSubClass();
  217.  
  218. itemCurrent = itemList[0];
  219. position = 0;
  220. this.displayOneItem(itemCurrent);
  221.  
  222.  
  223. }
  224. });
  225. return first;
  226. }
  227. }
  228. //Initialize "Last" button
  229. private JButton getLast() {
  230.  
  231. if (last == null) {
  232. last = new JButton("Last");
  233. last.addActionListener(new java.awt.event.ActionListener(){
  234. private Object item;
  235.  
  236. public void actionPerformed(java.awt.event.ActionEvent e) {
  237. last();
  238.  
  239. }
  240.  
  241. private void displayOneItem(StockSubClass itemCurrent) {
  242. String tempValue;
  243. labels[0].setText(item.getItemNumber() + "");
  244. labels[1].setText(item.getItemName());
  245. labels[2].setText(Long.toString(item.getItemQuantity()));
  246. tempValue = String.format("$%.2f", item.getItemPrice());
  247. labels[3].setText(tempValue);
  248. tempValue = String.format("$%.2f", item.calculateTotalItemValue());
  249. labels[4].setText(tempValue);
  250. tempValue = String.format("$%.2f", item.calculateRestockingFee());
  251. labels[5].setText(tempValue);
  252. tempValue = String.format("$%.2f", item.calculateInventoryValue());
  253. labels[6].setText(tempValue);
  254. labels[7].setText(item.getItemGenre());
  255. tempValue = String.format("$%.2f", StockSubClass.getTotalInventoryValue(itemList));
  256. labels[3].setText(tempValue);
  257.  
  258.  
  259.  
  260. }
  261.  
  262.  
  263.  
  264.  
  265.  
  266. private void last() {
  267. StockSubClass itemCurrent = new StockSubClass();
  268.  
  269. itemCurrent = itemList[MAXIMUM_ITEMS - 1];
  270. position = MAXIMUM_ITEMS - 1;
  271. this.displayOneItem(itemCurrent);
  272.  
  273. }
  274.  
  275. });
  276.  
  277.  
  278. return (JButton) last;
  279. }
  280. }
  281. private JButton Add() {
  282.  
  283. JButton Add = new JButton("Add");
  284. Add.addActionListener(new java.awt.event.ActionListener() {
  285. private Object stockInput;
  286. private Object NameText;
  287.  
  288. public void actionPerformed(ActionEvent e) {
  289. int index;
  290.  
  291. FeeQtyProduct temp = (FeeQtyProduct)
  292. stockInput.getFeeQtyProduct(index);
  293. int numberOfItems = stockInput.getNumberOfItems() +1;
  294.  
  295. index = (numberOfItems - 2 % numberOfItems);
  296. repaint GUI;
  297.  
  298. if(NameText.getText().equals("Add artist name")) {
  299. JOptionPane.showMessageDialog(null, "Please fill blank entry before adding more" +
  300. "\nRemember to push Modify when you finish with changes","Negative, the pattern is full",JOptionPane.ERROR_MESSAGE);
  301.  
  302. }
  303. if(NameText.getText().equals("Add Artist Name") !=true) {
  304.  
  305. FeeQtyProduct product = new FeeQtyProduct("Add artist name",
  306. Integer.parseInt(itemNumberText.getText())+1, 0, 0.0, "Add movie title");
  307.  
  308. index = (numItems - 1) % numItems;
  309. stockinput.addFeeQtyProduct(product);
  310. repaintGUI();
  311.  
  312. }
  313. if (numItems == 4)
  314.  
  315. {
  316. stockinput.removeFeeQtyProduct(temp);
  317. JOptionPane.showMessageDialog(null, "No more entries", JOptionPane.ERROR_MESSAGE);
  318. }
  319. }
  320. });
  321. }
  322. private JButton Save(){
  323.  
  324. JButton Save = new JButton("Save");
  325. Save.addActionListener(new java.awt.event.ActionListener() {
  326. private Object stockInput;
  327.  
  328. public void actionPerformed(ActionEvent e) {
  329.  
  330. int numItems = stockInput.getNumItems();
  331. Inventory Storage = new InventoryStorage();
  332.  
  333. title.openFile();
  334. int currentTitle = 0;
  335.  
  336. do {
  337. title.addTitle();
  338. currentTitle = currentTitle + 1;
  339. index = (++index) % numItems;
  340.  
  341. }
  342. while (currentTitle < numItems);
  343.  
  344. title.closeFile();
  345. }
  346. });
  347.  
  348. }
  349.  
  350.  
  351.  
  352.  
  353.  
  354. private JButton Modify() {
  355.  
  356. JButton Modify = new JButton("Modify");
  357. Modify.addActionListener(new java.awt.event.ActionListener() {
  358. private Object artistText;
  359. private Object numberText;
  360.  
  361.  
  362. public void actionPerformed(ActionEvent e) {
  363.  
  364. if (artistText.getText(.equals("")) {
  365.  
  366. JOptionPane.showMessageDialog(null, "Please complete entry", JOptionPane.ERROR_MESSAGE);
  367.  
  368. repaint GUI();
  369. }
  370. int MESSAGE();
  371. if (numberText.getText().equals("")) {
  372.  
  373. JOptionPane.showMessageDialog(null, "Please complete entry", JOptionPane.ERROR-MESSAGE);
  374.  
  375. repaint GUI();
  376. }
  377.  
  378. try {
  379.  
  380. Double.parseDouble(qtyText.getText());
  381. Double.parseDouble(priceText.getText());
  382.  
  383. }
  384. catch (Exception d) {
  385.  
  386. JOptionPane.showMessageDialog(null, "Recheck numbers entered for price and quantity", JOptionPane.ERROR-MESSAGE);
  387.  
  388. repaintGUI();
  389.  
  390. }
  391. String name; int number; double amount, price; String title;
  392.  
  393. name = NameText.getText();
  394. number = Integer.parseInt(temNumberText.getText());
  395. amount = Double.parseDouble(qtyText.getText());
  396. price = Double.parseDouble(priceText.getText());
  397. title = NameText.getText();
  398.  
  399. FeeQtyProduct modify = (FeeQtyProduct)
  400. stockinput.getFeeQtyProduct(index);
  401.  
  402. modify.setProductNumber(number);
  403. modify.setProductName(name);
  404. modify.setBaseAmount(amount);
  405. mosidy.setBasePrice(price);
  406. modify.setMovieTitle(title);
  407.  
  408. repaintGUI();
  409.  
  410. }
  411. });
  412.  
  413.  
  414.  
  415. }
  416. private JButton Delete() {
  417. JButton Delete = new JButton("Delete");
  418. Delete.addActionListener(new java.awt.event.ActionListener() {
  419.  
  420. public void actionPerformed(ActionEvent e) {
  421.  
  422. int numItems = stockInput.getNumItems();
  423. FeeQtyProduct temp = (FeeWtyProduct)
  424. stockInput.getFeeQtyProduct(index);
  425.  
  426. if (numItems != 0) {
  427.  
  428. if(Integer.parseInt(itemNumberText.getText())!= numItems) {
  429.  
  430. stockInput.remove(index);
  431. repaintGUI();
  432. int i = Integer.parseInt(itemNumberText.getText());
  433.  
  434. index = (++index) % numItems;
  435. repaintGUI();
  436. int j = Integer.parseInt(itemNumberText.getText());
  437.  
  438. if (i > j) {
  439. index = (--index) % numItems;
  440. }
  441. repaintGUI();
  442. temp == (FeeQtyProduct)stockInput.getFeeQtyProduct(index);
  443. temp.setProductNumber(j-1);
  444.  
  445. index = (++index) % numItems;
  446. repaintGUI();
  447.  
  448. }
  449.  
  450. if(Integer.parseInt(itemNumberText.getText())== numItems) {
  451.  
  452. stockInput.removeFeeQtyProduct(temp);
  453.  
  454. index = (++index) % numItems;
  455. repaint GUI();
  456. }
  457.  
  458. }
  459.  
  460. if (numItems == 1) {
  461.  
  462. FeeQtyProduct = new FeeQtyProduct("Add artist name", numItems, 0, 0.0, "Add movie title");
  463.  
  464. stockInput.addFeeQtyProduct(product);
  465.  
  466. JOptionPane.showMessageDialog(null, "Delete process complete", JOptionPane.ERROR_MESSAGE);
  467. repaintGUI();
  468.  
  469. }
  470.  
  471. }
  472.  
  473. });
  474.  
  475. }
  476.  
  477.  
  478.  
  479. }
  480.  
  481. //Display first item
  482. private void first() {
  483. StockSubClass itemCurrent = new StockSubClass();
  484.  
  485. itemCurrent = itemList[0];
  486. position = 0;
  487. this.displayOneItem(itemCurrent);
  488.  
  489.  
  490. }
  491.  
  492. //Display last item
  493. private void last() {
  494. StockSubClass itemCurrent = new StockSubClass();
  495.  
  496. itemCurrent = itemList[MAXIMUM_ITEMS - 1];
  497. position = MAXIMUM_ITEMS - 1;
  498. this.displayOneItem(itemCurrent);
  499.  
  500. }
  501.  
  502.  
  503.  
  504.  
  505.  
  506. //Display previous item
  507. private void previous() {
  508. StockSubClass itemCurrent = new StockSubClass();
  509. if (position != 0) {
  510. position--;
  511.  
  512. }
  513.  
  514. else {
  515. position = MAXIMUM_ITEMS - 1;
  516.  
  517. }
  518.  
  519. itemCurrent = itemList[position];
  520. this.displayOneItem(itemCurrent);
  521.  
  522. }
  523.  
  524. //Display next item
  525. private void next() {
  526. StockSubClass itemCurrent = new StockSubClass();
  527. if (position != (MAXIMUM_ITEMS - 1)) {
  528. position++;
  529.  
  530. }
  531. else {
  532. position = 0;
  533.  
  534. }
  535. itemCurrent = itemList[position];
  536. this.displayOneItem(itemCurrent);
  537.  
  538. }
  539.  
  540. //Display one item
  541. private void displayOneItem(StockSubClass item) {
  542. String tempValue;
  543. labels[0].setText(item.getItemNumber() + "");
  544. labels[1].setText(item.getItemName());
  545. labels[2].setText(Long.toString(item.getItemQuantity()));
  546. tempValue = String.format("$%.2f", item.getItemPrice());
  547. labels[3].setText(tempValue);
  548. tempValue = String.format("$%.2f", item.calculateTotalItemValue());
  549. labels[4].setText(tempValue);
  550. tempValue = String.format("$%.2f", item.calculateRestockingFee());
  551. labels[5].setText(tempValue);
  552. tempValue = String.format("$%.2f", item.calculateInventoryValue());
  553. labels[6].setText(tempValue);
  554. labels[7].setText(item.getItemGenre());
  555. tempValue = String.format("$%.2f", StockSubClass.getTotalInventoryValue(itemList));
  556. labels[3].setText(tempValue);
  557.  
  558.  
  559.  
  560. }
  561.  
  562. public void main(String[] args) {
  563. StockGui displayItem = new StockGui();
  564. displayItem.getJFrame();
  565. }
  566.  
  567. class InventoryStorage {
  568.  
  569. private Formatter output;
  570.  
  571. public void openFile() {
  572. try {
  573. String strDirectory ="C://data/";
  574.  
  575. boolean success = (new File(strDirectory));
  576.  
  577. if (success) {
  578. JOptionPane.showMessageDialog(null, "We created a directory named data in your C drive", JOptionPane.PLAIN_MESSAGE);
  579.  
  580. }
  581.  
  582. }
  583.  
  584. catch (Exception e) {
  585.  
  586. JOptionPane.showMessageDialog(null, "You do not have write access to the C: drive", JOptionPane.ERROR_MESSAGE);
  587.  
  588. }
  589.  
  590. try {
  591.  
  592. output = new Formatter("C:/data/inventory.dat");
  593.  
  594. }
  595.  
  596. catch (SecurityException securityException) {
  597.  
  598. JOptionPane.showMessageDialog(null, "You do not have write access to this file",JOptionPane.ERROR_MESSAGE);
  599.  
  600. System.exit(1);
  601.  
  602. }
  603.  
  604. catch(FileNotFoundException fileNotFoundException) {
  605.  
  606. JOptionPane.showMessageDialog(null, "Please create a file named data in your c drive", JOptionPane.ERROR_MESSAGE);
  607.  
  608. System.exit(1);
  609.  
  610. }
  611.  
  612. JOptionPane.showMessageDialog(null, "File saved successfully", JOptionPane.PLAIN_MESSAGE);
  613.  
  614. }
  615.  
  616. public void addItems() {
  617.  
  618. FeeQtyProduct Item = (FeeQtyProduct)stockInput.getFeeQtyProduct(index);
  619.  
  620.  
  621. BigDecimal roundPrice = new BigDecimal (Double.toStr5ing(item.restock()));
  622. roundPrice = roundPrice.setScale(2, RoundingMode.HALF_UP);
  623.  
  624. BigDecimal roundValue = new BigDecimal(Double.toString(item.total()));
  625. roundValue = roundValue.setScale(2,RoundingMode.HALF_UP);
  626.  
  627. BigDecimal roundTotal = new BigDecimal(Double.toString(stockInput.value()));
  628. roundTotal = roundTotal.setScale(2,RoundingMode.HALF_UP);
  629.  
  630. if (item != null){
  631. output.format("Artist: %s Product#: %s WTY#: %.OfPrice: $%.2f%s: %s",
  632. record.getItemName(), item.getItemNumber(), item.getItemAmount(), item.getItemPrice(),
  633. "Movie", item.getItemTitle() + "Inventory Total $" + (roundTotal) + "\t\n END OF LINE\t\t");
  634.  
  635. }
  636.  
  637. }
  638.  
  639. public void closeFile() {
  640.  
  641. if (output != null) {
  642. output.close();
  643. }
  644.  
  645. }
  646.  
  647.  
  648.  
  649. public void repaintGUI() {
  650.  
  651. FeeQtyProduct temp = (FeeQtyProduct)stockInput.getFeeQtyProduct(index);
  652.  
  653. if (temp != null){
  654.  
  655. itemNumberText.setText("" + temp.getProductNumber());
  656. artistText.setText(temp.getProductName());
  657. movieText.setText (String.format("%s", temp.getMovieTitle()));
  658. priceText.setText(String.format("%.2f", temp.getBasePrice()));
  659. restockFeeText.setText(String.format("$%.2f", temp.restock()));
  660. qtyText.setText(String.format("%.0f", temp.getBaseAmount()));
  661. valueText.setText(String.format("$%.2f", temp.total()));
  662.  
  663.  
  664. }
  665. totalValueText.setText(String.format("$%.2f", stock.Input.value()));
  666.  
  667.  
  668.  
  669.  
  670.  
  671. }
  672. }


These are the errors I am getting:


:\Documents and Settings\Tammy\My Documents\NetBeansProjects\Stock\src\stock\StockGui.java:368: illegal start of expression
if (artistText.getText(.equals("")) {
C:\Documents and Settings\Tammy\My Documents\NetBeansProjects\Stock\src\stock\StockGui.java:374: ')' expected
int MESSAGE();
C:\Documents and Settings\Tammy\My Documents\NetBeansProjects\Stock\src\stock\StockGui.java:379: ';' expected
repaint GUI();
C:\Documents and Settings\Tammy\My Documents\NetBeansProjects\Stock\src\stock\StockGui.java:446: not a statement
temp == (FeeQtyProduct)stockInput.getFeeQtyProduct(index);
C:\Documents and Settings\Tammy\My Documents\NetBeansProjects\Stock\src\stock\StockGui.java:459: ';' expected
repaint GUI();
C:\Documents and Settings\Tammy\My Documents\NetBeansProjects\Stock\src\stock\StockGui.java:486: 'class' or 'interface' expected
private void first() {
6 errors
BUILD FAILED (total time: 0 seconds)
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 1,672
Reputation: javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all 
Solved Threads: 225
Featured Poster
javaAddict's Avatar
javaAddict javaAddict is online now Online
Posting Virtuoso

Re: Final- Inventory program part 6

 
0
  #2
Jul 14th, 2008
illegal start of expression if (artistText.getText(.equals("")) {
if (artistText.getText().equals("")) {

C:\Documents and Settings\Tammy\My Documents\NetBeansProjects\Stock\src\stock\StockGui.java:374: ')' expected
int MESSAGE(); What are you trying to do here? Declare an int or call MESSAGE()

C:\Documents and Settings\Tammy\My Documents\NetBeansProjects\Stock\src\stock\StockGui.java:446: not a statement
temp == (FeeQtyProduct)stockInput.getFeeQtyProduct(index);
Try with 1 '=' the above is used to return boolean
Check out my New Bike at my Public Profile at the "About Me" tab
Reply With Quote Quick reply to this message  
Reply

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


Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC