Question

Java   Project -  Queue ADT Problem Statement and Assignment: Design an inventory class that stores the...

Java   Project -  Queue ADT

Problem Statement and Assignment:
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 (interfaces) for storing data into, and retrieving data from, these members.  
Then, design a program that uses the queue class.  The type of the queue should be the above inventory.  The program should have a loop that asks the user whether 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 information should be stored in an inventory object using inventory interfaces and added into the inventory queue.

If the user wishes to take a part from inventory, the program should remove the front part from the queue and display the contents of its member variables.

When the user finishes, the program should display the contents of the member values of all the objects that remain in the queue.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

package com.HomeworkLib1;

import java.util.Scanner;

class Inventory {
   PartsQueue inventoryQueue = new PartsQueue();

   public void addPartsToInventory(Parts item) {
       GenericNode node = new GenericNode(item);
       inventoryQueue.enqueue(node);
   }
  
   public Parts takePartsFromInventory() {
       return inventoryQueue.dequeue().data;
   }
  
   public void diplaayInventoryDetails() {
       inventoryQueue.printQueue();
   }

   public static void main(String[] args) {
       // TODO Auto-generated method stub
       Inventory inventory = new Inventory();
       Scanner console = new Scanner(System.in);
       // Add task
       boolean breakLoop = false;
       while(!breakLoop) {
           //Menu display
           System.out.println("Menu");
           System.out.println("1 Add parts to Inventory");
           System.out.println("2 Take parts from Queue");
           System.out.println("3 Display inventory details");
           System.out.println("4 Quit");
           System.out.print("Enter option: ");
          
           int option = console.nextInt();
          
           switch(option) {
           //Add employee to queue
           case 1:
               //Read Inventory details
               System.out.print("\nEnter Serial number:");
               int serialNum = console.nextInt();
              
               System.out.print("\nEnter date of manufacturing: ");
               String date = console.next();
               System.out.print("\nEnter lot number : ");
               int lotNo = console.nextInt();
               //Create Inventory object
               Parts part = new Parts(serialNum, date, lotNo);
              
               //Add to queue
               inventory.addPartsToInventory(part);
              
               break;
           case 2:
               //Remove from queue
               Parts removedPart = inventory.takePartsFromInventory();
               //Display detail
               System.out.println("Removed parts details from inventory: ");
               System.out.println(removedPart.toString());
               break;
           case 3:
               inventory.diplaayInventoryDetails();
               break;
           case 4:
               breakLoop = true;
               break;
           default:
               System.out.println("Wrong input");
           }
       }
   }
}
---------------------
package com.HomeworkLib1;

import java.util.Scanner;

class GenericNode {
   GenericNode next;
   Parts data;

   public GenericNode(Parts data) {
       this.data = data;
   }

}

class Parts {
   int serialNum;
   String manufactDate;
   int lotNum;

   /**
   * @param serialNum
   * @param manufactDate
   * @param lotNum
   */
   public Parts(int serialNum, String manufactDate, int lotNum) {
       super();
       this.serialNum = serialNum;
       this.manufactDate = manufactDate;
       this.lotNum = lotNum;
   }

   /*
   * (non-Javadoc)
   *
   * @see java.lang.Object#toString()
   */
   @Override
   public String toString() {
       return "Parts [serialNum=" + serialNum + ", "
               + (manufactDate != null ? "manufactDate=" + manufactDate + ", " : "") + "lotNum=" + lotNum + "]";
   }

}

public class PartsQueue {

   // Front and Rear Pointers to to point start and end of queue
   GenericNode front;
   GenericNode rear;
   double cost;

   // Enqueue methods
   void enqueue(GenericNode node) {

       // Create a new LL GenericNode
       GenericNode temp = node;

       // If queue is empty, then new GenericNode is front and rear both
       if (this.rear == null) {
           this.front = this.rear = temp;
           return;
       }

       // Add the new GenericNode at the end of queue and change rear
       this.rear.next = temp;
       this.rear = temp;
   }

   GenericNode dequeue() {
       // If queue is empty, return NULL.
       if (this.front == null)
           return null;

       // Store previous front and move front one GenericNode ahead
       GenericNode temp = this.front;
       this.front = this.front.next;

       // If front becomes NULL, then change rear also as NULL
       if (this.front == null)
           this.rear = null;
       return temp;
   }

   // Print queue method
   void printQueue() {
       GenericNode temp = front;
       while (temp != null) {
           System.out.println(temp.data.toString());
           temp = temp.next;
       }
   }

}
-------------------
Output
Menu
1 Add parts to Inventory
2 Take parts from Queue
3 Display inventory details
4 Quit
Enter option: 1

Enter Serial number:1000

Enter date of manufacturing: 12/12/2018

Enter lot number : 2000
Menu
1 Add parts to Inventory
2 Take parts from Queue
3 Display inventory details
4 Quit
Enter option: 1

Enter Serial number:1001

Enter date of manufacturing: 13/12/2018

Enter lot number : 2001
Menu
1 Add parts to Inventory
2 Take parts from Queue
3 Display inventory details
4 Quit
Enter option: 1

Enter Serial number:1002

Enter date of manufacturing: 14/12/2018

Enter lot number : 2003
Menu
1 Add parts to Inventory
2 Take parts from Queue
3 Display inventory details
4 Quit
Enter option: 2
Removed parts details from inventory:
Parts [serialNum=1000, manufactDate=12/12/2018, lotNum=2000]
Menu
1 Add parts to Inventory
2 Take parts from Queue
3 Display inventory details
4 Quit
Enter option: 1

Enter Serial number:1004

Enter date of manufacturing: 15/12/2018

Enter lot number : 2004
Menu
1 Add parts to Inventory
2 Take parts from Queue
3 Display inventory details
4 Quit
Enter option: 2
Removed parts details from inventory:
Parts [serialNum=1001, manufactDate=13/12/2018, lotNum=2001]
Menu
1 Add parts to Inventory
2 Take parts from Queue
3 Display inventory details
4 Quit
Enter option: 3
Parts [serialNum=1002, manufactDate=14/12/2018, lotNum=2003]
Parts [serialNum=1004, manufactDate=15/12/2018, lotNum=2004]
Menu
1 Add parts to Inventory
2 Take parts from Queue
3 Display inventory details
4 Quit
Enter option: 4

Add a comment
Know the answer?
Add Answer to:
Java   Project -  Queue ADT Problem Statement and Assignment: Design an inventory class that stores the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C# .netframework console application

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

  • You will design a program to keep track of a restaurants waitlist using a queue implemented...

    You will design a program to keep track of a restaurants waitlist using a queue implemented with a linked list. Create a class named waitList that can store a name and number of guests. Use constructors to automatically initialize the member variables. Add the following operations to your program: Return the first person in the queue Return the last person in the queue Add a person to the queue Delete a person from the queue Create a main program to...

  • solve this JAVA problem in NETBEANS Problem #12 in page 400 of your text (6th edition): SavingsAccount Class. Design a SavingsAccount class that stores a savings account's annual interest rate...

    solve this JAVA problem in NETBEANS Problem #12 in page 400 of your text (6th edition): SavingsAccount Class. Design a SavingsAccount class that stores a savings account's annual interest rate and balance. The class constructor should accept the amount of the savings account's starting balance. The class should also have methods for subtracting the amount of a withdrawal, adding the amount of a deposit, and adding the amount of monthly twelve. To add the monthly interest rate to the balance,...

  • Using java Create a simple queue class and a simple stack class. The queue and stack...

    Using java Create a simple queue class and a simple stack class. The queue and stack should be implemented as a linked list. Create three functions that utilize these data structures Write a function that opens a text file and reads its contents into a stack of characters. The program should then pop the characters from the stack and save them in a second text file. The order of the characters saved in the second file should be the reverse...

  • Written in java, Your Tasks: Design a class, NumericPalindrome, as an array-based queue. Hints Design a...

    Written in java, Your Tasks: Design a class, NumericPalindrome, as an array-based queue. Hints Design a driver class named HighestPalindromeProduct which uses class "NumericPalindrome" to find and display the highest number obtained as the product of two two-digit numbers, which is a palindrome. Display the result, indicating the product, as well as the two numbers that were used in the calculation. If you implement all the required methods properly, the driver program should generate outputs similar to the following: 99X91=9009...

  • C++ Programing In this exercise, you will design a class memberType. The class has the following...

    C++ Programing In this exercise, you will design a class memberType. The class has the following data members: memberName. A string that holds the name of a person memberID. A string that holds the member identification number numBooks. An int that holds the number of books bought purchaseAmt. A double that holds the amount spent on books In addition, the class should have the following constructor and other member functions. Constructor. The constructor should accept the person’s name and member...

  • Design and implement a Java data structure class named BookShelf which has an array to store...

    Design and implement a Java data structure class named BookShelf which has an array to store books and the size data member. The class should have suitable constructors, get/set methods, and the toString method, as well as methods for people to add a book, remove a book, and search for a book. Design and implement a Java class named Book with two data members: title and price. Test the two classes by creating a bookshelf object and five book objects....

  • To solve real world problem, the programer uses ADT like list, stack, queue, set, map, ... etc. t...

    To solve real world problem, the programer uses ADT like list, stack, queue, set, map, ... etc. to build our data model. In AS8, we pick and choose STL queue and stack to build a postfix calculator. In this assignment you are to Design your own linked-list, a series of integer nodes. The private attributes of this IntLinked Queue including a integer node struct and private control variables and methods: private: struct Node { int data; Node *next; }; Node...

  • In this assignment you will be implementing two Abstract Data Types (ADT) the Queue ADT and...

    In this assignment you will be implementing two Abstract Data Types (ADT) the Queue ADT and the Stack ADT. In addition, you will be using two different implementations for each ADT: Array Based Linked You will also be writing a driver to test your Queue and Stack implementations and you will be measuring the run times and memory use of each test case. You will also be adding some functionality to the TestTimes class that you created for Homework 1....

  • In C++, Step 1: Implement the Student Class and write a simple main() driver program to...

    In C++, Step 1: Implement the Student Class and write a simple main() driver program to instantiate several objects of this class, populate each object, and display the information for each object. The defintion of the student class should be written in an individual header (i.e. student.h) file and the implementation of the methods of the student class should be written in a corresponding source (i.e. student.cpp) file. Student class - The name of the class should be Student. -...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT