473,569 Members | 2,489 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can anyone else help with an Inventory program?

59 New Member
r03581x has been helping me with a program, but he won't be online till Monday, and I have to have this finished by tomorrow... Is there anyone else out there that can help me?

Here is the first half of what I have so far... I will post the rest of the code in a second post cause it is too long...

Expand|Select|Wrap|Line Numbers
  1. import java.util.*;
  2. import javax.swing.*;
  3. import java.awt.event.*;
  4. import java.awt.*;
  5.  
  6. class Product implements Comparable
  7. {
  8.     String name;         // class variable that stores the item name
  9.     double number;         // class variable that stores the item number
  10.     long stockQuantity; // class variable that stores the quantity in stock
  11.     double price;         // class variable that stores the item price
  12.     public Product()
  13.     {
  14.           name = "";
  15.         number = 0.0;
  16.         stockQuantity = 0L;
  17.         price = 0.0;
  18.      }
  19.  
  20.      public Product(String name, int number, long stockQuantity, double price)
  21.      {
  22.           this.name = name;
  23.         this.number = number;
  24.         this.stockQuantity = stockQuantity;
  25.         this.price = price;
  26.     }
  27.  
  28.     public void setItemName(String name)
  29.     {
  30.           this.name = name;
  31.      }
  32.  
  33.      public String getItemName()
  34.      {
  35.           return name;
  36.      }
  37.  
  38.      public void setItemNumber(double number)
  39.      {
  40.           this.number = number;
  41.      }
  42.  
  43.      public double getItemNumber()
  44.      {
  45.           return number;
  46.      }
  47.  
  48.      public void setStockQuantity(long quantity)
  49.      {
  50.           stockQuantity = quantity;
  51.      }
  52.  
  53.      public long getStockQuantity()
  54.      {
  55.           return stockQuantity;
  56.      }
  57.  
  58.      public void setItemPrice(double price)
  59.      {
  60.       this.price = price;
  61.      }
  62.  
  63.      public double getItemPrice()
  64.      {
  65.           return price;
  66.      }
  67.  
  68.      public double calculateInventoryValue()
  69.      {
  70.           return getItemPrice() * getStockQuantity();
  71.      }
  72.  
  73.      public int compareTo (Object o)
  74.      {
  75.           Product p = (Product)o;
  76.           return name.compareTo(p.getItemName());
  77.      }
  78.  
  79.      public String toString()
  80.      {
  81.           return "\nName: "+getItemName() + "\nNumber: "+number+"\nPrice: $"+price+"\nQuantity: "+stockQuantity + "\nValue: $"+calculateInventoryValue();
  82.      }
  83. }//end Product
  84.  
  85. class MobilePhone extends Product implements Comparable
  86. {
  87.     private String brand;
  88.     public MobilePhone()
  89.     {
  90.     super(); //call the constructor in Product
  91.     brand = ""; //add the additonal attribute
  92.     }
  93.  
  94.     public MobilePhone(String name, int number, long stockQuantity, double price, String brand)
  95.     {
  96.         super(name, number, stockQuantity, price); //call the constructor in Product
  97.         this.brand = brand; //add the additonal attribute
  98.     }
  99.  
  100.     public void setBrand(String brand)
  101.     {
  102.         this.brand = brand;
  103.     }
  104.  
  105.     public String getBrand()
  106.     {
  107.         return brand;
  108.     }
  109.  
  110.     public double calculateInventoryValue()
  111.     {
  112.         return getItemPrice() * getStockQuantity();
  113.     }
  114.  
  115.     public double calculateRestockFee()
  116.     {
  117.         return getItemPrice() * 0.05;
  118.     }
  119.  
  120.     public int compareTo (Object o)
  121.     {
  122.         Product p = (Product)o;
  123.         return getItemName().compareTo(p.getItemName());
  124.     }
  125.  
  126.     public String toString()
  127.     {
  128.         return "\nName: "+getItemName() + "\nNumber: "+getItemNumber()+"\nPrice: $"+getItemPrice()+"\nQuantity: "+getStockQuantity() +"\nBrand: "+getBrand()+"\nValue: $"+calculateInventoryValue();
  129.     }
  130. }//end MobilePhone
Dec 8 '06 #1
2 2883
zaidalin79
59 New Member
Here is the seconf half of the code...

Expand|Select|Wrap|Line Numbers
  1. public class Inventory10 extends JFrame implements ActionListener
  2. {
  3.     //utility class for displaying the picture
  4.     private class MyPanel extends JPanel
  5.     {
  6.         ImageIcon image = new ImageIcon("Sample.jpg");
  7.         int width = image.getIconWidth();
  8.         int height = image.getIconHeight();
  9.         long angle = 30;
  10.         public MyPanel()
  11.         {
  12.             super();
  13.         }
  14.  
  15.         public void paintComponent(Graphics g)
  16.         {
  17.              super.paintComponent(g);
  18.              Graphics2D g2d = (Graphics2D)g;
  19.              g2d.rotate (Math.toRadians(angle), 60+width/2, 60+height/2);
  20.              g2d.drawImage(image.getImage(), 60, 60, this);
  21.              g2d.dispose();
  22.         }
  23.  
  24.     }//end class MyPanel
  25.  
  26.     int currentIndex; //currently displayed Item
  27.     Product[] supplies = new Product[4];
  28.     JLabel name ;
  29.     JLabel number;
  30.     JLabel brand;
  31.     JLabel quantity;
  32.     JLabel price;
  33.     JLabel fee;
  34.     JLabel totalValue;
  35.     JTextField nameField = new JTextField(20);
  36.     JTextField numberField = new JTextField(20);
  37.     JTextField brandField = new JTextField(20);
  38.     JTextField quantityField = new JTextField(20);
  39.     JTextField priceField = new JTextField(20);
  40.  
  41.     JPanel display;
  42.     JPanel displayHolder;
  43.     JPanel panel;
  44.  
  45.     public Inventory10()
  46.     {
  47.         makeTheDataItems();
  48.         setSize(500, 500);
  49.         setTitle("Audrey's Inventory Program v1.0");
  50.  
  51.         //make the panels
  52.         display = new JPanel();
  53.         JPanel other = new JPanel();
  54.         JPanel picture = new MyPanel();
  55.         JPanel buttons = new JPanel();
  56.         JPanel centerPanel = new JPanel();
  57.         displayHolder = new JPanel();
  58.         display.setLayout(new GridLayout(3, 3));
  59.         other.setLayout(new GridLayout(2, 1));
  60.  
  61.         //make the labels
  62.         name = new     JLabel("Name        :");
  63.         number = new     JLabel("Number     :");
  64.         brand = new     JLabel("Brand     :");
  65.         quantity = new JLabel("Quantity    :");
  66.         price = new     JLabel("Price     :");
  67.         fee = new        JLabel("Fee         :");
  68.         totalValue = new JLabel("Total Value :");
  69.  
  70.         //make the buttons
  71.         JButton first = makeButton("First");
  72.         JButton next = makeButton("Next");
  73.         JButton previous = makeButton("Previous");
  74.         JButton last = makeButton("Last");
  75.         JButton exit = makeButton("Exit");
  76.  
  77.         //other buttons
  78.         JButton add = makeButton("Add");
  79.  
  80.         //add the labels to the display panel
  81.         display.add(name);
  82.         display.add(number);
  83.         display.add(brand);
  84.         display.add(quantity);
  85.         display.add(price);
  86.         display.add(fee);
  87.  
  88.         //add the buttons to the buttonPanel
  89.         buttons.add(first);
  90.         buttons.add(previous);
  91.         buttons.add(next);
  92.         buttons.add(last);
  93.         buttons.add(exit);
  94.  
  95.         //add the picture panel and display to the centerPanel
  96.         displayHolder.add(display);
  97.         centerPanel.setLayout(new GridLayout(2, 1));
  98.         centerPanel.add(picture);
  99.         centerPanel.add(displayHolder);
  100.         other.add(buttons);
  101.         JPanel forAdd = new JPanel(); // add the other buttons to this panel
  102.         forAdd.add(add);
  103.         other.add(forAdd);
  104.  
  105.         //add the panels to the frame
  106.         getContentPane().add(centerPanel, "Center");
  107.         getContentPane().add(other, "South");
  108.         this.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
  109.         setVisible(true);
  110.  
  111.     }//end Inventory10
  112.  
  113.     private void makeTheDataItems ()
  114.     {
  115.           supplies[0] = new MobilePhone("3310", 001, 200, 200, "Nokia");
  116.           supplies[1] = new MobilePhone("T720", 002, 500, 250, "Motorola");
  117.           supplies[2] = new MobilePhone("5110C", 003, 35, 149, "LG");
  118.           supplies[3] = new MobilePhone("9400D", 004, 90, 300, "Samsung");
  119.     }
  120.  
  121.     //method for creating and dressing buttons
  122.     private JButton makeButton(String label)
  123.     {
  124.         JButton button = new JButton(label);
  125.         button.setActionCommand(label);
  126.         button.addActionListener(this);
  127.         return button;
  128.     }
  129.  
  130.     private void addItem()
  131.     {
  132.         System.out.println("eeeeeeeeee");
  133.         panel = new JPanel();
  134.         JPanel add = new JPanel();
  135.         add.setLayout(new GridLayout(2, 1));
  136.         add.setLayout(new GridLayout(4, 4));
  137.         JButton addIt = makeButton("Add Item");
  138.         JLabel name = new JLabel("Name        :");
  139.         //JLabel number = new JLabel("Number     :");
  140.         JLabel brand = new JLabel("Brand     :");
  141.         JLabel quantity = new JLabel("Quantity    :");
  142.         JLabel price = new JLabel("Price     :");
  143.         add.add(name); add.add(nameField);
  144.         //add.add(number); add.add(numberField);
  145.         add.add(brand); add.add(brandField);
  146.         add.add(quantity); add.add(quantityField);
  147.         add.add(price); add.add(priceField);
  148.         panel.add(add);
  149.         JPanel forAddIt = new JPanel();
  150.         forAddIt.add(addIt);
  151.         panel.add(forAddIt);
  152.         displayHolder.remove(display);
  153.         displayHolder.add(panel);
  154.         //display = panel;
  155.         this.setVisible(true);
  156.     }//end addItem
  157.  
  158.      // main methods begins execution of java application
  159.     public static void main( String args[])
  160.     {
  161.         Inventory10 object = new Inventory10();
  162.     } // end main method
  163.  
  164.     public void actionPerformed(ActionEvent event)
  165.     {
  166.         String command = event.getActionCommand(); //retrieves command set for the button
  167.  
  168.         if(command.equals("First"))
  169.         {
  170.             displayFirst();
  171.         }
  172.         else if(command.equals("Next"))
  173.         {
  174.             displayNext();
  175.         }
  176.         else if(command.equals("Previous"))
  177.         {
  178.             displayPrevious();
  179.         }
  180.         else if(command.equals("Last"))
  181.         {
  182.             displayLast();
  183.         }
  184.         else if(command.equals("Exit"))
  185.         {
  186.             this.dispose();
  187.             System.exit(0);
  188.         }
  189.         else if(command.equals("Add"))
  190.         {
  191.             addItem();
  192.         }
  193.         else if(command.equals("Add Item"))
  194.         {
  195.             addItemToArray();
  196.         }
  197.  
  198.     }//end action method
  199.  
  200.     private void addItemToArray()
  201.     {
  202.         Product p = new MobilePhone(nameField.getText(), supplies.length -2, Long.parseLong(quantityField.getText()),
  203.         Double.parseDouble(priceField.getText()), brandField.getText());
  204.  
  205.         //extend size of array by one first
  206.         Product[] ps = new Product[supplies.length + 1];
  207.         for(int i = 0; i < ps.length-1; i++)
  208.         {
  209.             ps[i] = supplies[i];
  210.         }
  211.         ps[supplies.length] = p;
  212.         supplies = ps;
  213.         displayHolder.remove(panel);
  214.         displayHolder.add(display);
  215.         displayLast();
  216.         this.setVisible(false);
  217.         this.setVisible(true);
  218.     }//end addItem
  219.  
  220.     //utility method to reduce lines of code
  221.     private void displayItemAt(int index)
  222.     {
  223.         MobilePhone product = (MobilePhone)supplies[index];
  224.         name.setText("Item Name: "+ product.getItemName());
  225.         number.setText("Item Number: "+ product.getItemNumber());
  226.         brand.setText("Brand: "+ product.getBrand());
  227.         quantity.setText("Quantity In Stock: "+ product.getStockQuantity());
  228.         price.setText("Item Price: "+ product.getItemPrice());
  229.         totalValue.setText("Total: " + product.calculateInventoryValue());
  230.         fee.setText("Fee :"+product.calculateRestockFee());
  231.         this.setVisible(true);
  232.     }
  233.  
  234.     public void displayFirst()
  235.     {
  236.         displayItemAt(0);
  237.         currentIndex = 0;
  238.     }
  239.  
  240.     public void displayNext()
  241.     {
  242.         if(currentIndex == supplies.length-1)
  243.         {
  244.             displayFirst();
  245.             currentIndex = 0;
  246.         }
  247.         else
  248.         {
  249.             displayItemAt(currentIndex + 1);
  250.             currentIndex++;
  251.         }
  252.     }
  253.  
  254.     public void displayPrevious()
  255.     {
  256.         if(currentIndex == 0)
  257.         {
  258.             displayLast();
  259.             currentIndex = supplies.length-1;
  260.         }
  261.         else
  262.         {
  263.             displayItemAt(currentIndex - 1);
  264.             currentIndex--;
  265.         }
  266.     }
  267.  
  268.     public void displayLast()
  269.     {
  270.         displayItemAt(supplies.length-1);
  271.         currentIndex = supplies.length-1;
  272.     }
  273. }//end class Inventory10
Dec 8 '06 #2
zaidalin79
59 New Member
Here is what I need it to do...

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 :\data\inventor y.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.

If anyone can help me at all I would really apreciate it so much!!! Thanks
Dec 8 '06 #3

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

Similar topics

2
1577
by: porky008 | last post by:
I can not figure out how to use an array to store the different things and the total is only showing 0.0 instead of the total of the inventory. Can I please get some help on this? // This calls the external class scanner import java.util.Scanner; class inventory { // start of class // Variable Declaration private String...
38
4182
by: JenniferT | last post by:
OK, so I'm very new to Java programming and I've been able to squeek by so far, but I'm completely stuck on this assignment. Here is the assignment that is due this week - • 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,...
67
22933
by: hollywoood | last post by:
I am trying to add the Delete button, save and search buttons. I have tried to call my teacher and he is absolutly no help and i have read and reread the text but still have no idea what is going on.........I have the added the add button but now i am stuck. Is there a simple way in completeing this?? Please help • Due Date: Day 7 forum •...
5
2505
by: Sam | last post by:
Hi, I have one table like : MyTable {field1, field2, startdate, enddate} I want to have the count of field1 between startdate and enddate, and the count of field2 where field2 = 1 between startdate and enddate, all in the same query.
1
2810
by: twin2003 | last post by:
need help with inventory part 5 here is what I have to do 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...
9
7599
by: xxplod | last post by:
I am suppose to 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...
11
7682
by: hamiltongreg | last post by:
I am new to Java and am having problems getting my program to compile correctly. My assignment is as follows; Choose a product that lends itself to an inventory (for example, products at your workplace, office supplies, music CDs, DVD movies, or software). • Create a product class that holds the item number, the name of the product, the...
2
2058
by: hamiltongreg | last post by:
I am pretty new to Java and have a question about where to begin with my program. The assignment is to 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...
2
4429
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...
0
7618
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...
0
7926
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8132
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...
1
7678
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...
0
7982
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...
0
5222
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...
0
3656
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...
0
3644
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1226
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.