473,386 Members | 1,752 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Can anyone else help with an Inventory program?

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 2879
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
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\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.

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
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...
38
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...
67
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...
5
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...
1
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...
9
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...
11
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...
2
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...
2
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...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
0
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...

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.