473,791 Members | 3,137 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Inventory Program Part 6

8 New Member
I'm having some trouble with my inventory program. Its due tom and my teacher is not wanting to help. He keeps giving me a soluction that is not related to my code. I have everything working except the Delete and Modify Button. The Search button works but it only searchs the new .dat file or what is set in the array. Not sure what is going on there. But if I can get my delete and modify button to work that will be good.

Code....

Expand|Select|Wrap|Line Numbers
  1.  
  2. import javax.swing.JFrame;
  3. import java.awt.*;
  4. import javax.swing.*;
  5. import java.awt.event.*;
  6. import java.io.*;
  7. import java.text.NumberFormat;
  8. import javax.swing.border.*;
  9. import java.net.*;
  10. import java.util.StringTokenizer;
  11.  
  12. // Begin Inventory Class
  13.  
  14. class Inventory  extends JFrame  implements Serializable
  15. {
  16.     private Container cp = getContentPane(); 
  17.     private static int ItemNumber[] = new int[100];
  18.     private static String name[] = new String[100];
  19.     private static int Quantity[] = new int[100];
  20.     private static double Price[] = new double[100];
  21.     private static int i = 0;
  22.  
  23.     public Inventory(){
  24.         setLayout(new FlowLayout());
  25.     }
  26.  
  27.     public Inventory(int _ItemNumber, String _name, int _Quantity, double _Price)
  28.     {         
  29.         ItemNumber[i] = _ItemNumber;
  30.         name[i] = _name;
  31.         Quantity[i] = _Quantity;
  32.         Price[i] = _Price;
  33.         i = i + 1;
  34.     }    
  35.     public static int getItemNumber(int k)                // Get ItemNumber
  36.     {                                                   
  37.         return ItemNumber[k];                            // Return ItemNumber
  38.     }
  39.     public static String getItemName(int k)                // Get ItemName
  40.     {
  41.         return name[k];                                    // Return name
  42.     }
  43.     public static int getItemQuantity(int k)            // Get Item Quantity
  44.     {
  45.         return Quantity[k];                                // Return Quantity
  46.     }
  47.     public static double getItemPrice(int k)             // Get ItemPrice
  48.     {
  49.         return Price[k];                                  // Return Price
  50.     }
  51.     public static void setItemNumber(int k,int value)       //Set ItemNumber
  52.     {
  53.         ItemNumber[k] = value;
  54.     }
  55.     public static void setItemName(int k,String value)        // Set ItemName
  56.     {
  57.         name[k] = value;
  58.     }
  59.     public static void setItemQuantity(int k,int value)        // Set ItemQuantity
  60.     {
  61.         Quantity[k] = value;
  62.     }
  63.     public static void setItemPrice(int k,double value)         // Set ItemPrice
  64.     {
  65.         Price[k] = value;
  66.     }
  67.  
  68.     public static void DeleteItem(int k)                            // DeleteItem  old DeleteItemName
  69.     {
  70.         for(int j=k;j<getCount()-1;j++)
  71.         {
  72.             setItemNumber(j,getItemNumber(j+1));
  73.             setItemName(j,getItemName(j+1));
  74.             setItemQuantity(j,getItemQuantity(j+1));
  75.             setItemPrice(j,getItemPrice(j+1));
  76.         }
  77.  
  78.         i-=1;
  79.  
  80.  
  81.     }
  82.     public static int SearchItem(String value)                                 // Search Item     old SearchItemName
  83.     {
  84.         int k = -1;
  85.  
  86.         for(int j=0;j<getCount();j++)
  87.         {
  88.             if(getItemName(j).equals(value))
  89.                 k = j;
  90.         }
  91.         return k;
  92.     }    
  93.  
  94.     public static double valueOfInventory(double p,int u)                            // value of Inventory
  95.     {
  96.         return p*u;
  97.     }
  98.  
  99.  
  100.     public static void swap(int j, int min)
  101.     {
  102.         String tmp;
  103.         tmp = name[j];
  104.         name[j] = name[min];
  105.         name[min] = tmp;
  106.  
  107.         int temp = ItemNumber[j];
  108.         ItemNumber[j] = ItemNumber[min];
  109.         ItemNumber[min] = temp;
  110.  
  111.         temp = Quantity[j];
  112.         Quantity[j] = Quantity[min];
  113.         Quantity[min] = temp;
  114.  
  115.         double temp1 = Price[j];
  116.         Price[j] = Price[min];
  117.         Price[min] = temp1;
  118.  
  119.     }
  120.                                                                                             // Show Value of Inventory
  121.  
  122.     public double showValueofInventory()
  123.     {
  124.         double totalVal = 0;
  125.         for (int j = 0; j < getCount(); j++)
  126.         {
  127.             totalVal = totalVal + valueOfInventory(Price[j], Quantity[j]);
  128.         }
  129.         return totalVal;        
  130.     }
  131.  
  132.     public static int getCount()
  133.     {
  134.         return i;
  135.     }
  136.  
  137. }  // End Inventory Class
  138.  
  139. // Begin Products Class
  140.  
  141. class Products implements Serializable
  142. {
  143.     public static double valueOfInventory(double p, double u,double rf)
  144.     {
  145.         double vOfI = (p * u) + (p*u*rf);
  146.         return (vOfI );
  147.     }
  148.  
  149.     public static double valueOfRestockFee(double p, double rf)
  150.     {
  151.         double percent = 0;
  152.         percent = (p * 5) / 100;
  153.         return percent;
  154.     }
  155.  
  156. }     // End Products Class
  157.  
Dec 8 '07 #1
5 3378
cblank
8 New Member
More Code...

Expand|Select|Wrap|Line Numbers
  1.  
  2. // Being PC Class
  3.  
  4. class PC extends Inventory implements ActionListener,Serializable
  5.  
  6.     static String manufacture[] = new String[100];                        // Subclass to add to Workstation - Manufacture 
  7.     static String Workstation_Type[] = new String[100];                    // Subclass to add to Workstation - Workstation Type
  8.     static double restockingFee[] = new double[100];                    // Restock Fee to add to inventory value
  9.     static int i;                                                        //removed     = 0;
  10.     static double TotalVal;
  11.     static int navItem;
  12.     static Boolean isRecordLoadedFromFile = false;
  13.  
  14.     private Container cp = getContentPane();
  15.  
  16.     GridBagConstraints c;
  17.     GridBagConstraints cconstraint ;    
  18.     Border titledborder;
  19.     JPanel pan,pan2;
  20.  
  21.     String labels[] ={"ID:","Manufacture:", "Workstation ID:", "Workstation Name:","Workstation Type:", "Quantity:", "Price: $", "Restocking Fee: $", "Workstation Inventory Value with Fee: $", "Total Workstation Value with Fee: $" };    // field names
  22.     int len1 = labels.length;
  23.     JLabel lbl[] = new JLabel[len1];
  24.     JTextField txtfield1[] = new JTextField[len1];
  25.  
  26.     String blabels[] ={ "First", "Previous", "Next", "Last" };      //Bottom Buttons
  27.     int blen = blabels.length;
  28.     JButton navigate[] = new JButton[blen];
  29.  
  30.     String cmdlabels[] ={"Load File", "Add", "Modify", "Delete", "Search", "Save","Cancel" };     // Tops Buttons
  31.     int cmdlen = cmdlabels.length;
  32.     JButton cmdbutton[] = new JButton[cmdlen];
  33.  
  34.     JLabel lblImg;
  35.     File file;
  36.     public String FileName;
  37.  
  38.     public PC(String Manufacture,String Workstation_ID, double restockingFee, int Item_Number, String Item_Name, int Items_in_Stock, double Item_Price)
  39.  
  40.     {
  41.         super(Item_Number, Item_Name, Items_in_Stock, Item_Price);
  42.         this.manufacture[i] = Manufacture;
  43.         this.Workstation_Type[i] = Workstation_ID;
  44.         this.restockingFee[i] = restockingFee;
  45.         i = i + 1;
  46.     }
  47.  
  48.     public String toString()
  49.  
  50.     {
  51.         StringBuffer sb = new StringBuffer("\nManufacture: ").append(manufacture).append("\n");
  52.         sb.append(super.toString());
  53.  
  54.         return sb.toString();
  55.     }
  56.  
  57.     public static double getRestockFee(int val)
  58.  
  59.     {
  60.         return restockingFee[val];
  61.     }
  62.  
  63.     public static void setWorkstation_ID(int k,String value)
  64.  
  65.     {
  66.         Workstation_Type[k] = value;
  67.     }
  68.  
  69.     public static void setManufacture(int k,String value)
  70.  
  71.     {
  72.         manufacture[k] = value;
  73.     }
  74.  
  75.     public static String getWorkstation_ID(int k)                    // Get Workstation_ID
  76.  
  77.     {
  78.         return Workstation_Type[k];                                     // Return Workstation Type
  79.     }
  80.  
  81.     public static String getManufacture(int k)                         // Get Manufacture
  82.  
  83.     {
  84.         return manufacture[k];                                         // Return Manufacture
  85.     }
  86.  
  87.  
  88.     public static void DeleteItem(int k)                              // Delete PC Item
  89.  
  90.     {
  91.         for(int j=k;j<getCount()-1;j++)
  92.         {
  93.             setItemNumber(j,getItemNumber(j+1));
  94.             setItemName(j,getItemName(j+1));
  95.             setItemQuantity(j,getItemQuantity(j+1));
  96.             setItemPrice(j,getItemPrice(j+1));
  97.             setWorkstation_ID(j,getWorkstation_ID(j+1));
  98.             setManufacture(j,getManufacture(j+1));
  99.         }
  100.  
  101.          i = i - 1;
  102.  
  103.     }
  104.  
  105.     public void ShowInvent()  
  106.     {            
  107.         setLayout(new FlowLayout());        
  108.  
  109.         GridBagLayout contlayout = new GridBagLayout();                    // layout for container
  110.         GridBagConstraints cconstraint = new GridBagConstraints();        // constraint for container
  111.  
  112.         GridBagLayout gblayout = new GridBagLayout();                    // layout for panel
  113.         GridBagConstraints gbconstraint = new GridBagConstraints();        // constraint for container
  114.  
  115.  
  116.         FileName = "C://data//inventory.dat";                             // .dat file
  117.  
  118.         try
  119.         {
  120.             String strDirectoy = "C://data";                                 // start location
  121.             boolean success = (new File(strDirectoy)).mkdir();
  122.             file = new File(FileName);
  123.             success = file.createNewFile();
  124.  
  125.             // Add Top Buttons
  126.             pan = new JPanel();
  127.             gblayout = new GridBagLayout();
  128.             gbconstraint = new GridBagConstraints();
  129.             pan.setLayout(gblayout);
  130.  
  131.             gbconstraint.gridwidth = 1;
  132.             gbconstraint.gridheight = 1;
  133.             gbconstraint.gridy = 0;
  134.  
Dec 8 '07 #2
cblank
8 New Member
More Code

Expand|Select|Wrap|Line Numbers
  1. for (int i = 0; i < cmdlen; i++)
  2.             {
  3.                 cmdbutton[i] = new JButton(cmdlabels[i]);
  4.                 cmdbutton[i].addActionListener(this);
  5.                 gbconstraint.gridx = i;
  6.                 pan.add(cmdbutton[i], gbconstraint);
  7.             }
  8.  
  9.             titledborder = BorderFactory.createTitledBorder("Main Navigation");
  10.             pan.setBorder(titledborder);
  11.  
  12.             // add panel to container
  13.             cconstraint.gridwidth = 4;
  14.             cconstraint.gridheight = 1;
  15.             cconstraint.gridx = 0;
  16.             cconstraint.gridy = 2;
  17.             cp.add(pan, cconstraint);
  18.             // addition complete
  19.  
  20.             //create first panel
  21.             pan = new JPanel();
  22.             gblayout = new GridBagLayout();
  23.             gbconstraint = new GridBagConstraints();
  24.             pan.setLayout(gblayout);
  25.  
  26.             for (int i = 0; i < 2; i++)
  27.             {
  28.                 for (int j = 0; j < len1; j++)
  29.                 {
  30.                     int x = i;
  31.                     int y = j;
  32.                     if (x == 0)
  33.                     {
  34.                         lbl[j] = new JLabel(labels[j]);
  35.                         lbl[j].setHorizontalAlignment(JLabel.LEFT);
  36.                         lbl[j].setPreferredSize(new Dimension(250, 15));
  37.                         gbconstraint.insets = new Insets(10, 0, 0, 0);
  38.                         gbconstraint.gridx = x;
  39.                         gbconstraint.gridy = y;
  40.                         pan.add(lbl[j], gbconstraint);
  41.                     }
  42.                     else
  43.                     {
  44.                         txtfield1[j] = new JTextField(15);
  45.                         txtfield1[j].setHorizontalAlignment(JLabel.LEFT);
  46.                         txtfield1[j].setEnabled(false);
  47.                         lbl[j].setLabelFor(txtfield1[j]);
  48.                         gbconstraint.gridx = x;
  49.                         gbconstraint.gridy = y;
  50.                         pan.add(txtfield1[j], gbconstraint);
  51.                     }
  52.                 }
  53.             } // first panel done
  54.  
  55.  
  56.             Border titledborder = BorderFactory.createTitledBorder("Workstation Inventory Information");   // Title - Border
  57.             pan.setBorder(titledborder);
  58.  
  59.             // main panel
  60.             cconstraint.gridwidth = 1;
  61.             cconstraint.gridheight = 1;
  62.             cconstraint.gridx = 0;
  63.             cconstraint.gridy = 0;
  64.             cp.add(pan, cconstraint);
  65.             // main panel created.
  66.  
  67.             // add image to panel
  68.             pan = new JPanel();
  69.             gblayout = new GridBagLayout();
  70.             gbconstraint = new GridBagConstraints();
  71.             pan.setLayout(gblayout);
  72.  
  73.             gbconstraint.gridwidth = 1; gbconstraint.gridheight = 1;
  74.             gbconstraint.gridy = 0;
  75.  
  76.             lblImg = new JLabel((new ImageIcon(getClass().getResource("pclogo.jpg"))));     // logo
  77.             lblImg.setPreferredSize(new Dimension(120, 120));
  78.             pan.add(lblImg);
  79.  
  80.             cconstraint.gridwidth = 1;
  81.             cconstraint.gridheight = 1;
  82.             cconstraint.gridx = 0;
  83.             cconstraint.gridy = 1;
  84.             cp.add(pan, cconstraint);
  85.             // image added
  86.  
  87.  
  88.             //Create Bottom Button Panel
  89.             pan = new JPanel();
  90.             gblayout = new GridBagLayout();
  91.             gbconstraint = new GridBagConstraints();
  92.             pan.setLayout(gblayout);
  93.                gbconstraint.gridwidth = 1; gbconstraint.gridheight = 1;
  94.             gbconstraint.gridy = 0;
  95.  
  96.             for (int i = 0; i < blen; i++)
  97.             {
  98.                 navigate[i] = new JButton(blabels[i]);
  99.                 gbconstraint.gridx = i;
  100.                 pan.add(navigate[i], gbconstraint);
  101.  
  102.                 navigate[i].addActionListener(this);
  103.             }
  104.  
  105.             titledborder = BorderFactory.createTitledBorder("Button Navigation"); // bottom button navigation
  106.             pan.setBorder(titledborder);
  107.             // Bottom Button Panel Created
  108.  
  109.             // add panel to container
  110.             cconstraint.gridwidth = 4;
  111.             cconstraint.gridheight = 1;
  112.             cconstraint.gridx = 1;
  113.             cconstraint.gridy = 1;
  114.             cp.add(pan, cconstraint);
  115.             // panel added    
  116.         }
  117.         catch (Exception e)
  118.         {
  119.             e.printStackTrace();
  120.         }
  121.     }
  122.     public void setContents(File aFile, String aContents)
  123.     {
  124.         BufferedWriter output = null;
  125.         try
  126.         {
  127.             //use buffering
  128.             output = new BufferedWriter(new FileWriter(aFile, true));
  129.             output.write(aContents);
  130.             String newLine = System.getProperty("line.separator");
  131.             output.write(newLine);
  132.         }
  133.  
  134.         catch (Exception ex)
  135.         {
  136.             ex.printStackTrace();
  137.         }
  138.  
  139.         finally
  140.         {
  141.             try
  142.             {
  143.                 //Buffering
  144.                 if (output != null) output.close();
  145.             }
  146.             catch (java.io.IOException e)
  147.             {
  148.                 e.printStackTrace();
  149.             }
  150.         }
  151.     }
  152.     public void AddModifyInventory(String Mode)
  153.     {
  154.         if (Mode.equals("Insert"))
  155.         {
  156.             String Content = txtfield1[1].getText() + "\t" + txtfield1[2].getText() + "\t" + txtfield1[3].getText() + "\t" + txtfield1[4].getText() + "\t" + txtfield1[5].getText() + "\t" + txtfield1[6].getText();
  157.             setContents(file, Content);
  158.             JOptionPane.showMessageDialog(null, "Item Successfully Inserted");
  159.         }
  160.     }
  161.     public void ShowInventory(int ItemNo)
  162.     {
  163.         txtfield1[0].setText(Integer.toString(ItemNo));
  164.         txtfield1[1].setText(manufacture[ItemNo]);
  165.         txtfield1[2].setText(Integer.toString(Inventory.getItemNumber(ItemNo)));
  166.         txtfield1[3].setText(Inventory.getItemName(ItemNo)); 
  167.         txtfield1[4].setText(Workstation_Type[ItemNo]); 
  168.         txtfield1[5].setText(Integer.toString(Inventory.getItemQuantity(ItemNo)));
  169.         txtfield1[6].setText(Double.toString(Inventory.getItemPrice(ItemNo)));
  170.         txtfield1[7].setText(String.format("%3.2f", Products.valueOfRestockFee(Inventory.getItemPrice(ItemNo), getRestockFee(ItemNo))));
  171.         txtfield1[8].setText(String.format("%3.2f", Products.valueOfInventory(Inventory.getItemPrice(ItemNo), Inventory.getItemQuantity(ItemNo), getRestockFee(ItemNo))));
  172.         txtfield1[9].setText(String.format("%3.2f",GetTotalInvVal()));
  173.     }
  174.     public void EnableFields(boolean bflag)
  175.     {
  176.     //        txtfield1[0].setEnabled(bflag);
  177.             txtfield1[1].setEnabled(bflag);
  178.             txtfield1[2].setEnabled(bflag);
  179.             txtfield1[3].setEnabled(bflag);
  180.             txtfield1[4].setEnabled(bflag);
  181.             txtfield1[5].setEnabled(bflag);
  182.             txtfield1[6].setEnabled(bflag);
  183.     }
  184.  
  185.     public double GetTotalInvVal()
  186.     {
  187.         TotalVal = 0;
  188.         for (int j = 0; j < Inventory.getCount(); j++)
  189.         {
  190.             TotalVal += Products.valueOfInventory(Inventory.getItemPrice(j), Inventory.getItemQuantity(j), getRestockFee(j));
  191.         }
  192.         return TotalVal;
  193.     }
  194.     public Integer GetRecordCount()
  195.     {
  196.         FileReader fr;
  197.         BufferedReader br;
  198.         LineNumberReader lnr;
  199.         String line;
  200.         int lno = 0;
  201.  
  202.         try
  203.         {
  204.             lnr = new LineNumberReader(new BufferedReader(new FileReader(FileName)));
  205.  
  206.             while ((line = lnr.readLine()) != null)
  207.             {
  208.                 lno = lnr.getLineNumber();
  209.             }
  210.  
  211.             lnr.close();
  212.         }
  213.         catch (IOException ioErr)                                                          
  214.         {
  215.             System.out.println(ioErr.toString());
  216.             System.exit(100);
  217.         }
  218.         return lno;
  219.     }
  220.     public void showInventory(int itemNo)
  221.     {
  222.         int i;
  223.         FileReader fr;
  224.         BufferedReader br;
  225.         LineNumberReader lnr;
  226.         StringTokenizer st;
  227.         String line;
  228.         int item = itemNo + 1;
  229.  
  230.         int ItemNo = 0;
  231.         int Items = 0;
  232.         String ItemManufacture = "";
  233.         String ItemName = "";
  234.         String ItemWorkstation_ID = "";
  235.         double ItemPric = 0;
  236.         double Total = 0;
  237.         Integer rFee = 0;
  238.         int lno;
  239.  
Dec 8 '07 #3
cblank
8 New Member
More Code

Expand|Select|Wrap|Line Numbers
  1.  
  2. try
  3.         {
  4.             lnr = new LineNumberReader(new BufferedReader(new FileReader(FileName)));
  5.  
  6.             while ((line = lnr.readLine()) != null)
  7.             {
  8.                 lno = lnr.getLineNumber();
  9.  
  10.  
  11.                 String s1[];
  12.                 if (item == lno)
  13.                 {
  14.                     s1 = new String[lno];
  15.                     s1[0] = line;
  16.                     st = new StringTokenizer(s1[0]);
  17.                     ItemManufacture = st.nextToken();                    
  18.                     ItemNo = Integer.parseInt(st.nextToken());
  19.                     ItemName = st.nextToken();
  20.                     ItemWorkstation_ID = st.nextToken();
  21.                     Items = Integer.parseInt(st.nextToken());
  22.                     ItemPric = Double.parseDouble(st.nextToken());
  23.  
  24.                 }
  25.                 s1 = new String[lno];
  26.                 s1[0] = line;
  27.                 st = new StringTokenizer(s1[0]);
  28.                 st.nextToken();
  29.                 st.nextToken();
  30.                 st.nextToken();
  31.                 st.nextToken();
  32.                 Integer Quantity = Integer.parseInt(st.nextToken());
  33.                 Double Price = Double.parseDouble(st.nextToken());
  34.                 Total += Products.valueOfInventory(Price, Quantity, 0.05);
  35.             }
  36.  
  37.             lnr.close();
  38.         }
  39.         catch (IOException ioErr)
  40.         {
  41.             System.out.println(ioErr.toString());
  42.             System.exit(100);
  43.         }
  44.  
  45.         txtfield1[0].setText(Integer.toString(itemNo));
  46.         txtfield1[1].setText(ItemManufacture);
  47.         txtfield1[2].setText(Integer.toString(ItemNo));
  48.         txtfield1[3].setText(ItemName);
  49.         txtfield1[4].setText(ItemWorkstation_ID);
  50.         txtfield1[5].setText(Integer.toString(Items));
  51.         txtfield1[6].setText(Double.toString(ItemPric));
  52.         txtfield1[7].setText(String.format("%3.2f", Products.valueOfRestockFee(ItemPric, 0.05)));
  53.         txtfield1[8].setText(String.format("%3.2f", Products.valueOfInventory(ItemPric, Items, 0.05)));
  54.         txtfield1[9].setText(String.format("%3.2f", Total));        
  55.     }
  56.  
  57.     public void actionPerformed(ActionEvent e) // button navigation
  58.     {
  59.         String btnClicked = ((JButton)e.getSource()).getText();
  60.  
  61.  
  62.         if(btnClicked.equals("First"))               // First Button
  63.         {
  64.  
  65.             EnableFields(false);
  66.             if (isRecordLoadedFromFile)
  67.             {
  68.                 navItem = 0;
  69.                 showInventory(navItem);
  70.             }
  71.             else
  72.             {
  73.                 navItem = 0;
  74.                 ShowInventory(navItem);
  75.             }
  76.         }
  77.         if (btnClicked.equals("Next"))                   // Next Button
  78.         {
  79.             EnableFields(false);
  80.             if (isRecordLoadedFromFile)
  81.             {
  82.                 if (navItem == GetRecordCount() - 1)
  83.                 {
  84.                     navItem = 0;
  85.                 }
  86.                 else
  87.                 {
  88.                     navItem += 1;
  89.                 }
  90.                 if ((GetRecordCount() - 1) >= navItem)
  91.                     showInventory(navItem);
  92.                 else
  93.                     showInventory(GetRecordCount() - 1);
  94.             }
  95.             else
  96.             {
  97.                 if (navItem == getCount() - 1)
  98.                 {
  99.                     navItem = 0;
  100.                 }
  101.                 else
  102.                 {
  103.                     navItem += 1;
  104.                 }
  105.                 ShowInventory(navItem);
  106.             }
  107.         }
  108.         if (btnClicked.equals("Previous"))                 // Previous Button
  109.         {
  110.             EnableFields(false);
  111.             if (isRecordLoadedFromFile)
  112.             {
  113.                 if (navItem == 0)
  114.                 {
  115.                     navItem = GetRecordCount() - 1;
  116.                 }
  117.                 else
  118.                 {
  119.                     navItem = navItem - 1;
  120.                 }
  121.                 showInventory(navItem);
  122.             }
  123.             else
  124.             {
  125.                 if (navItem == 0)
  126.                 {
  127.                     navItem = getCount() - 1;
  128.                 }
  129.                 else
  130.                 {
  131.                     navItem = navItem - 1;
  132.                 }
  133.                 ShowInventory(navItem);
  134.             }
  135.         }
  136.         if (btnClicked.equals("Last"))                     // Last Button
  137.         {
  138.             EnableFields(false);
  139.             if (isRecordLoadedFromFile)
  140.             {
  141.                 navItem = GetRecordCount() - 1;
  142.                 showInventory(navItem);
  143.             }
  144.             else
  145.             {
  146.                 navItem = getCount() - 1;
  147.                 ShowInventory(navItem);
  148.             }
  149.         }
  150.         if (btnClicked.equals("Save"))                    // Save Button
  151.         {
  152.             AddModifyInventory("Insert");                 // Insert Button
  153.         }
  154.         if (btnClicked.equals("Load File"))                  // Load File Button
  155.         {
  156.             isRecordLoadedFromFile = true;
  157.             if (GetRecordCount() == 0)
  158.             {
  159.                 JOptionPane.showMessageDialog(null, "No Records Found In File");                
  160.             }
  161.             else
  162.             {
  163.                 showInventory(0);
  164.             }
  165.         }
  166.         if (btnClicked.equals("Cancel"))            // Cancel Button
  167.         {
  168.             EnableFields(false);
  169.             cmdbutton[4].setText("Search");            // Search Button
  170.             cmdbutton[2].setText("Modify");            // Modify Button
  171.             cmdbutton[1].setText("Add");            // Add Button
  172.             if(isRecordLoadedFromFile)
  173.                 showInventory(navItem);
  174.             else
  175.                 ShowInventory(navItem);
  176.         }
  177.         if(btnClicked.equals("Delete"))                 // Deleve Button
  178.         {
  179.             DeleteItem(Integer.parseInt(txtfield1[0].getText()));
  180.             navItem = getCount() -1;
  181.             JOptionPane.showMessageDialog(null, "Item Successfully Deleted");         // Field Update
  182.             ShowInventory(navItem);
  183.         }
  184.         if(btnClicked.equals("Search"))          // Search Button
  185.         {
  186.             cmdbutton[4].setText("GO!");      // Go Button
  187.             txtfield1[3].setEnabled(true);    
  188.         }
  189.         if(btnClicked.equals("GO!"))             // Go Button
  190.         {
  191.             boolean valid = true;
  192.             if (txtfield1[3].getText().trim().length() == 0)
  193.             {
  194.                 JOptionPane.showMessageDialog(null, "Workstation Name Required");      // Field Required
  195.                 valid = false;
  196.             }
  197.             if(valid)
  198.             {
  199.  
  200.                 int k = Inventory.SearchItem(txtfield1[3].getText().trim());
  201.                 if(k>=0)
  202.                 {
  203.                     txtfield1[0].setText(Integer.toString(k));
  204.                     txtfield1[1].setText(manufacture[k]);
  205.                     txtfield1[2].setText(Integer.toString(Inventory.getItemNumber(k)));
  206.                     txtfield1[3].setText(Inventory.getItemName(k));
  207.                     txtfield1[4].setText(Workstation_Type[k]);
  208.                     txtfield1[5].setText(Integer.toString(Inventory.getItemQuantity(k)));
  209.                     txtfield1[6].setText(Double.toString(Inventory.getItemPrice(k)));
  210.                     txtfield1[7].setText(String.format("%3.2f", Products.valueOfRestockFee(Inventory.getItemPrice(k), getRestockFee(k))));
  211.                     txtfield1[8].setText(String.format("%3.2f", Products.valueOfInventory(Inventory.getItemPrice(k ), Inventory.getItemQuantity(k), getRestockFee(k))));
  212.                     txtfield1[9].setText(String.format("%3.2f",GetTotalInvVal()));
  213.                     EnableFields(false);
  214.                     cmdbutton[4].setText("Search");    
  215.  
  216.                 }
  217.                 else
  218.                 {
  219.                     JOptionPane.showMessageDialog(null, "No Matches Found");    
  220.                     cmdbutton[4].setText("Search");    
  221.                     EnableFields(false);
  222.                 }
  223.             }            
  224.         }
  225.         if(btnClicked.equals("Modify"))         // Modify Button
  226.         {
  227.             EnableFields(true);
  228.  
  229.             cmdbutton[2].setText("Click to Edit!");
  230.         }
  231.         if(btnClicked.equals("Click to Edit!"))
  232.         {
  233.             Boolean valid = true;
  234.             if (txtfield1[1].getText().trim().length() == 0)
  235.             {
  236.                 JOptionPane.showMessageDialog(null, "Manufacture Required");   // Require Filed
  237.                 valid = false;
  238.             }
  239.             try
  240.             {
  241.                 Integer.parseInt(txtfield1[2].getText());
  242.             }
  243.             catch (Exception ex)
  244.             {
  245.                 JOptionPane.showMessageDialog(null, "Invalid Item Number - Only Number Allowed");      // Require Field
  246.                 txtfield1[3].setText("");
  247.                 valid = false;
  248.             }
  249.  
  250.             if (txtfield1[3].getText().trim().length() == 0)
  251.             {
  252.                 JOptionPane.showMessageDialog(null, "Workstation ID  Required");                      // Require Field
  253.                 valid = false;
  254.             }
  255.  
  256.             if (txtfield1[4].getText().trim().length() == 0)
  257.             {
  258.                 JOptionPane.showMessageDialog(null, "Workstation Type Required");                        // Require Field
  259.                 valid = false;
  260.             }
  261.  
  262.             try
  263.             {
  264.                 Integer.parseInt(txtfield1[5].getText());
  265.             }
  266.             catch (Exception ex)
  267.             {
  268.                 JOptionPane.showMessageDialog(null, "Invalid Quantity in Stock - Only Numbers Allowed");      // Require Field
  269.                 txtfield1[4].setText("");
  270.                 valid = false;
  271.             }
  272.             try
  273.             {
  274.                 Double.parseDouble(txtfield1[6].getText());
  275.             }
  276.             catch (Exception ex)
  277.             {
  278.                 JOptionPane.showMessageDialog(null, "Invalid Price - Only Numbers Allowed");                     // Require Field
  279.                 txtfield1[5].setText("");
  280.                 valid = false;
  281.             }
  282.  
  283.             if (valid)
  284.             {
  285.  
  286.                 //PC.setManufacture(navItem,txtfield1[1].getText());
  287.                 Inventory.setItemNumber(navItem,Integer.parseInt(txtfield1[2].getText()));
  288.                 Inventory.setItemName(navItem,txtfield1[3].getText());
  289.                 setWorkstation_ID(navItem,txtfield1[4].getText());
  290.                 Inventory.setItemQuantity(navItem,Integer.parseInt(txtfield1[5].getText()));
  291.                 Inventory.setItemPrice(navItem,Double.parseDouble(txtfield1[6].getText()));    
  292.  
  293.                 txtfield1[6].setText(String.format("%3.2f", Products.valueOfRestockFee(Inventory.getItemPrice(navItem), getRestockFee(navItem))));
  294.                 txtfield1[7].setText(String.format("%3.2f", Products.valueOfInventory(Inventory.getItemPrice(navItem ), Inventory.getItemQuantity(navItem), getRestockFee(navItem))));
  295.                 txtfield1[8].setText(String.format("%3.2f",GetTotalInvVal()));
  296.                 EnableFields(false);
  297.                 cmdbutton[2].setText("Modify");
  298.  
  299.             }
  300.         }
  301.         if (btnClicked.equals("Add"))
  302.         {
  303.             EnableFields(true);
  304.             txtfield1[0].setText(Integer.toString(getCount()));
  305.             txtfield1[1].requestFocus();
  306.  
  307.             txtfield1[1].setText("");
  308.             txtfield1[2].setText("");
  309.             txtfield1[3].setText("");
  310.             txtfield1[4].setText("");
  311.  
  312.             txtfield1[5].setText("0");
  313.             txtfield1[6].setText("0.00");
  314.             cmdbutton[1].setText("Click to Add!");
  315.         }
  316.         if (btnClicked.equals("Click to Add!"))
  317.         {
  318.             Boolean valid = true;
  319.             if (txtfield1[1].getText().trim().length() == 0)
  320.             {
  321.                 JOptionPane.showMessageDialog(null, "Manufacture Required");                       // Require Field
  322.                 valid = false;
  323.             }
  324.             try
  325.             {
  326.                 Integer.parseInt(txtfield1[2].getText());
  327.             }
  328.             catch (Exception ex)
  329.             {
  330.                 JOptionPane.showMessageDialog(null, "Invalid Item Number - Only Number Numbers Allowed");         // Require Field
  331.                 txtfield1[3].setText("");
  332.                 valid = false;
  333.             }
  334.  
  335.             if (txtfield1[3].getText().trim().length() == 0)
  336.             {
  337.                 JOptionPane.showMessageDialog(null, "Workstation ID Required");                                      // Require Field
  338.                 valid = false;
  339.             }
  340.  
  341.             if (txtfield1[4].getText().trim().length() == 0)
  342.             {
  343.                 JOptionPane.showMessageDialog(null, "Workstation Name Required");                                     // Require Field
  344.                 valid = false;
  345.             }
  346.  
  347.             try
  348.             {
  349.                 Integer.parseInt(txtfield1[5].getText());
  350.             }
  351.             catch (Exception ex)
  352.             {
  353.                 JOptionPane.showMessageDialog(null, "Invalid Quanity - Only Numbers Allowed");                           // Require Field
  354.                 txtfield1[4].setText("");
  355.                 valid = false;
  356.             }
  357.             try
  358.             {
  359.                 Double.parseDouble(txtfield1[6].getText());
  360.             }
  361.             catch (Exception ex)
  362.             {
  363.                 JOptionPane.showMessageDialog(null, "Invalid Price - Only Numbers Allowed");                             // Require Field
  364.                 txtfield1[5].setText("");
  365.                 valid = false;
  366.             }
  367.  
  368.             if (valid)
  369.             {
  370.                 PC r = new PC(txtfield1[1].getText(),txtfield1[4].getText(), 0.05, Integer.parseInt(txtfield1[2].getText()), txtfield1[3].getText(), Integer.parseInt(txtfield1[5].getText()), 
  371.                 Double.parseDouble(txtfield1[6].getText()));
  372.                 txtfield1[7].setText(String.format("%3.2f", Products.valueOfRestockFee(Inventory.getItemPrice(getCount() - 1), getRestockFee(getCount() - 1))));
  373.                 txtfield1[8].setText(String.format("%3.2f", Products.valueOfInventory(Inventory.getItemPrice(getCount() -1 ), Inventory.getItemQuantity(getCount() -1), getRestockFee(getCount() - 1))));
  374.                 txtfield1[9].setText(String.format("%3.2f",GetTotalInvVal()));
  375.                 navItem = getCount() - 1;
  376.                 EnableFields(false);
  377.                 cmdbutton[1].setText("Add");
  378.             }
  379.         }
  380.  
  381.  
  382.  
  383.     }
  384.  
  385. } // End PC Class
  386.  
  387.  
Dec 8 '07 #4
cblank
8 New Member
Last One

Expand|Select|Wrap|Line Numbers
  1. import java.io.InputStreamReader;
  2. import java.io.BufferedReader;
  3. import java.io.IOException;
  4. import javax.swing.JFrame;
  5.  
  6. //begin InvenotoryMain Class
  7.  
  8.  class InventoryMain
  9. {
  10.      public static void main( String[] args){
  11.  
  12.         double restockFee = 0.05;     // restock fee
  13.  
  14.     //array Information
  15.  
  16.         PC p = new PC("Dell","Home",restockFee, 100,"Dell-4400" , 10, 599.00);
  17.  
  18.         p.ShowInvent();
  19.         p.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  20.         p.setVisible(true);
  21.         p.setSize(550, 600);
  22.  
  23.      }
  24.  
  25. }    // end InventoryMain Class
  26.  
Dec 8 '07 #5
cblank
8 New Member
I know this is a lot to ask for in a short notice, but I have worked really hard until now and I just wish my teacher could he me its the last part of the program and I just want to do good in my class. Thanks, If someone could just tell me which part I need to look at and might need to change would help.

Thanks,
Dec 8 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

109
25898
by: zaidalin79 | last post by:
I have a java class that goes for another week or so, and I am going to fail if I can't figure out this simple program. I can't get anything to compile to at least get a few points... Here are the assignments... 4. CheckPoint: Inventory Program Part 1 • Resource: Java: How to Program • Due Date: Day 5 forum • Choose a product that lends itself to an inventory (for example, products at your workplace, office supplies, music CDs, DVD...
0
7117
by: south622 | last post by:
I'm taking a beginning Java course and I'm stuck in week eight of a nine week course. If anyone could help me I would greatly appreciate it. This assignment was due yesterday and each day I go past the due date 10% of the grade is taken off. I think I'm coming down with the flu and my brain is just not processing this assignment. Here is the assignment: Modify the Inventory program by adding a button to the GUI that allows the user to move...
3
1684
MonolithTMA
by: MonolithTMA | last post by:
Greetings all, I am new here, and aside from my introductory post, this will be my first. I am working on an Inventory program for a class I am taking. I've searched the forums here and have seen other people working on the same or similar projects, but the problem I run into is that in Java, there seems to be more than one way to skin a cat. (No cats were harmed in the writing of this post.) I am able to enter multiple items and their...
10
5856
by: mistb2002 | last post by:
I am trying to modify my program to add and delete inventory items. I tried just adding but I am getting mutliple errors help. This is what my program currently looks like // Display The DVDs. import java.text.*; import java.util.*; import java.awt.*; import java.awt.FlowLayout;
3
7010
by: cblank | last post by:
I need some help if someone could help me. I know everyone is asking for help in java. But for some reason I'm the same as everyone else when it comes to programming in java. I have an inventory program that I have built so far with no problem. But I cannot figure out how to turn it into a GUI application. This is what I'm trying to get it to do. Modify the Inventory Program to use a GUI. The GUI should display the information one product...
2
2543
by: pinkf24 | last post by:
I cannot figure out how to add the following: 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...
3
4488
by: 100grand | last post by:
Modify the Inventory Program to use a GUI. The GUI should display the information one product at a time, including the item number, the name of the product, the number of units in stock, the price of each unit, and the value of the inventory of that product. In addition, the GUI should display the value of the entire inventory, the additional attribute, and the restocking fee. Here is my Inventory program from 1 to 3: package...
2
4447
by: blitz1989 | last post by:
Hello all, I'm new to this forum and Java and having a alot of problems understanding this language. I am working on an invetory program part 4. The assignment requirements are listed but the reading has very little in it that helps can someone take a look at this code and point me in the right direction please. Thanks for any help that is offered. //Modify the Inventory Program to use a GUI. The GUI should display the //informationone...
16
6006
by: lilsugaman | last post by:
I have to assignment which includes the following: Modify the Inventory Program so the application can handle multiple items. Use an array to store the items. The output should display the information one product at a time, including the item number, the name of the product, the number of units in stock, the price of each unit, and the value of the inventory of that product. In addition, the output should display the value of the entire...
0
9669
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9515
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10207
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10155
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9995
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9029
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6776
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5431
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3718
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.