Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Inventory Bin Stack You have been hired by Company X, Inc to develop an inventor

ID: 3803940 • Letter: I

Question

Inventory Bin Stack

You have been hired by Company X, Inc to develop an inventory control system. The following are some guidelines and specifications. You may expand upon these (make sure that the specifications are covered) and be as creative as you like!

Design an inventory class that stores the following members:

serialNum:An integer that holds a part's serial number.

manufactDate:A member that holds the date the part was manufactured.

lotNum:An integer that holds the part's lot number.

The class should have appropriate member functions for storing data into, and retrieving data from, these members.

Next, design a stack class that can hold objects of the class described above.

Last, design a program that uses the stack class described above. The program should have a loop that asks the user if he or she wishes to add a part to inventory, or take a part from inventory. The loop should repeat until the user is finished.

If the user wishes to add a part to inventory, the program should ask for the serial number, date of manufacture, and lot number. The data should be stored in an inventory object, and pushed onto the stack.

If the user wishes to take a part from inventory, the program should pop the top-most part from the stack and display the contents of its member variables.

When the user finishes the program, it should display the contents of the member values of all the objects that remain on the stack.

Finally, once you have completed your lab, analyze your algorithms. Provide a brief review of your stack and explain the time complexity of the individual functions (pop & push).

A sample output is provided below:

----------------------Iventory Menu----------------------------

1. Enter a part into the inventory.

2. Take a part from the inventory.

3. Quit.

Please make a choice(1, 2,or 3): 1

You have chosen to add an item to iventory bin.

Enter the item's serial number: 43

Enter the item's manufacture data: 3/12/2015

----------------------Iventory Menu----------------------------

1. Enter a part into the inventory.

2. Take a part from the inventory.

3. Quit.

Please make a choice(1, 2, or 3): 3

Goodbye!

Explanation / Answer

InventoryItem.java:

import java.util.Date;

public class InventoryItem {
   private int serialNum;
   private Date manufacDate;
   private int lotNum;
   public InventoryItem(int serialNum, Date manufacDate, int lotNum) {
       this.serialNum = serialNum;
       this.manufacDate = manufacDate;
       this.lotNum = lotNum;
   }
   public int getSerialNum() {
       return serialNum;
   }
   public Date getManufacDate() {
       return manufacDate;
   }
   public int getLotNum() {
       return lotNum;
   }
  
   public String toString() {
       return "SerialNum: " + serialNum + ", Manufacture Date: " + manufacDate + ", Lot Num: " + lotNum;
   }
}



InventoryStack.java:

public class InventoryStack {
   private Node head;

   InventoryStack() {
       head = null;
   }

   void pushItem(InventoryItem item) {
       Node n = new Node(item);
       n.next = head;
       head = n;
   }

   InventoryItem popItem() {
       if(head == null)
           return null;
      
       Node n = head;
       head = head.next;
       return n.getItem();
   }

   public Node getHead() {
       return head;
   }

   class Node {
       InventoryItem item;
       Node next;

       public Node(InventoryItem item) {
           this.item = item;
       }

       public InventoryItem getItem() {
           return item;
       }
   }
}


InventoryDemo.java:

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

public class InventoryDemo {
   static Scanner scanner = new Scanner(System.in);
   static SimpleDateFormat dateFormat = new SimpleDateFormat("dd-mm-yyyy");

   public static void main(String[] args) {
       InventoryStack inventoryList = new InventoryStack();

       int choice = showMenuAndGetChoice();
       while (choice != 3) {
           if (choice == 1) {
               enterItemToInventory(inventoryList);
           } else if (choice == 2) {
               getItemFromInventory(inventoryList);
           }

           choice = showMenuAndGetChoice();
       }

   }

   private static void getItemFromInventory(InventoryStack inventoryList) {
       InventoryItem item = inventoryList.popItem();
       if (item != null) {
           System.out.println("Part from Inventory: ");
           System.out.println(item);
       } else {
           System.out.println("No Part is present in inventory");
       }
   }

   private static void enterItemToInventory(InventoryStack inventoryList) {
       System.out.println("You have chosen to add an item to iventory bin.");
       System.out.print("Enter the item's serial number: ");
       int serial = Integer.parseInt(scanner.nextLine());

       boolean validDate = false;
       Date date = null;
       while (!validDate) {
           System.out.print("Enter the item's manufacture data(dd-mm-yyyy): ");
           try {
               date = dateFormat.parse(scanner.nextLine());
               validDate = true;
           } catch (ParseException e) {
               System.out.println("Invalid Date. try Again.");
           }
       }
       System.out.print("Enter the lot number: ");

       int lot = Integer.parseInt(scanner.nextLine());
       InventoryItem item = new InventoryItem(serial, date, lot);
       inventoryList.pushItem(item);
   }

   private static int showMenuAndGetChoice() {
       String s = "----------------------Inventory Menu---------------------------- ";
       s += "1. Enter a part into the inventory. ";
       s += "2. Take a part from the inventory. ";
       s += "3. Quit. ";
       s += "Please make a choice(1, 2,or 3): ";

       int choice = 0;
       String message = "";
       while (choice < 1 || choice > 3) {
           System.out.println(message + s);
           choice = Integer.parseInt(scanner.nextLine());
           message = "Invalid Choice. ";
       }
       return choice;
   }

}

Sample Output:

----------------------Inventory Menu----------------------------
1. Enter a part into the inventory.
2. Take a part from the inventory.
3. Quit.
Please make a choice(1, 2,or 3):
1
You have chosen to add an item to iventory bin.
Enter the item's serial number: 1234
Enter the item's manufacture data(dd-mm-yyyy): 12-03-2015
Enter the lot number: 3421
----------------------Inventory Menu----------------------------
1. Enter a part into the inventory.
2. Take a part from the inventory.
3. Quit.
Please make a choice(1, 2,or 3):
1
You have chosen to add an item to iventory bin.
Enter the item's serial number: 5678
Enter the item's manufacture data(dd-mm-yyyy): 12-04-2016
Enter the lot number: 8765
----------------------Inventory Menu----------------------------
1. Enter a part into the inventory.
2. Take a part from the inventory.
3. Quit.
Please make a choice(1, 2,or 3):
2
Part from Inventory:

SerialNum: 5678, Manufacture Date: Tue Jan 12 00:04:00 IST 2016, Lot Num: 8765
----------------------Inventory Menu----------------------------
1. Enter a part into the inventory.
2. Take a part from the inventory.
3. Quit.
Please make a choice(1, 2,or 3):
2
Part from Inventory:

SerialNum: 1234, Manufacture Date: Mon Jan 12 00:03:00 IST 2015, Lot Num: 3421
----------------------Inventory Menu----------------------------
1. Enter a part into the inventory.
2. Take a part from the inventory.
3. Quit.
Please make a choice(1, 2,or 3):
2
No Part is present in inventory
----------------------Inventory Menu----------------------------
1. Enter a part into the inventory.
2. Take a part from the inventory.
3. Quit.
Please make a choice(1, 2,or 3):
3

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote