Question

In: Computer Science

Program Specification Design an inventory class that stores the following members: serialNum: An integer that holds...

Program Specification
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 setter and getter functions.

Next, design a stack class that can hold objects of the class described above. If you wish, you may use the linked list from program 5 as a basis for designing your stack.

Finally, 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 the object should be 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. When the user finishes the program, it should display the contents of the member values of all the objects that remain on the stack.

All i need in the display function not the whole program.In python.

Solutions

Expert Solution

To create a stack class that will keep inventory objects in the stack, We first have to create an inventory class.

I have coded everything to make a proper functional stack that will add to inventory, take from inventory and additionally show the items from the inventory and at last exit when the user wants.

import datetime

class inventory(object):
    def __init__(self,serialNum=None,lotNum=None,dom=None):
        self.serialNum = serialNum
        self.lotNum = lotNum
        self.dom = dom
        
    # getter method 
    def get_serialNum(self): 
        return self.serialNum 
      
    # setter method 
    def set_serialNum(self, x):
        self.serialNum =  x
        
    # getter method 
    def get_lotNum(self): 
        return self.lotNum
      
    # setter method 
    def set_lotNum(self, x):
        self.lotNum =  x
        
    # getter method 
    def get_dom(self):
        return self.dom
      
    # setter method 
    def set_dom(self, x):
        self.dom =  x

Below is the stack used :

class stack:
    def __init__(self):
        self.stack = []
        
    def push(self,inv_obj):
        self.stack.insert(0,inv_obj)
    
    def pop(self):
        del self.stack[0]

Additional Functions:

def get_date():
    dom = input("Enter date of manufacture [dd/mm/yyyy]: ")
    try:
        dom = datetime.datetime.strptime(dom,"%d/%m/%Y").date()
        return dom
    except:
        print("Invalid Date Format, Please enter mentioned date format:")
        return get_date()
            
def create_inventory():
    serialNum = input("Enter Serial Num: ")
    dom = get_date()
    lotNum = input("Enter Lot Num: ")
    inv = inventory()
    inv.set_lotNum(lotNum)
    inv.set_dom(dom)
    inv.set_serialNum(serialNum)
    st.push(inv)
    
def pop_inventory():
    st.pop()
    
def show_inventory():
    print("\n Inventory Items:")
    for item in st.stack:
        print("Serial Num: ",item.get_serialNum())
        print("Date of manufacture: ",item.get_dom())
        print("Lot Num: ",item.get_lotNum())
        print(20*"--")

Now the one last Display function which will combine all:

def display():
    while(1):
        print(20*"==")
        print("1. Add to inventory.")
        print("2. Take from inventory.")
        print("3. Show inventory.")
        print("4. Stop.")
        val = input("Choose from above options: ")
        if(val=='1'):
            create_inventory()
        elif(val=='2'):
            pop_inventory()
        elif(val=='3'):
            show_inventory()     
        elif(val=='4'):
            break
        else:
            print("Invalid Entry, Please select from [1,2,3,4]: ")

Now, let's make a stack object and call the display function:

st = stack()

display()

With this we completed the coding part and now let's see some sample outputs when we call display function.

With this, I hope you got the idea to go ahead with your problem.

Thanks and have a nice day!!

Below, I have attached all coding screenshots to avoid any indentation issues:


Related Solutions

Given the following specification, design a class diagram using PlantUML. To design the class diagram, use...
Given the following specification, design a class diagram using PlantUML. To design the class diagram, use abstract, static, package, namespace, association, and generalization on PlantUML Specification: A school has a principal, many students, and many teachers. Each of these persons has a name, birth date, and may borrow and return books. The book class must contain a title, abstract, and when it is available. Teachers and the principal are both paid a salary. A school has many playgrounds and rooms....
Consider the following program specification: Input: An integer n > 0 and an array A[0..(n –...
Consider the following program specification: Input: An integer n > 0 and an array A[0..(n – 1)] of n integers. Output: The largest index b such that A[b] is the largest value in A[0..(n – 1)]. For example, if n = 10 and A = [ 4, 8, 1, 3, 8, 5, 4, 7, 1, 2 ] (so A[0] = 4, A[1] = 8, etc.), then the program would return 4, since the largest value in A is 8 and...
Design a Ship class that the following members: A field for the name of the ship...
Design a Ship class that the following members: A field for the name of the ship (a string). A field for the year that the ship was built (a string). A constructor and appropriate accessors and mutators. A toString method that displays the ship’s name and the year it was built. Design a CruiseShip class that extends the Ship class. The CruiseShip class should have the following members: A field for the maximum number of passengers (an int). A constructor...
Design a Ship class that has the following members: • A member variable for the name...
Design a Ship class that has the following members: • A member variable for the name of the ship (a string) • A member variable for the year that the ship was built (a string) • A constructor and appropriate accessors and mutators • A virtual print function that displays the ship’s name and the year it was built. Design a CruiseShip class that is derived from the Ship class. The CruiseShip class should have the following members: • A...
Java program Test Scores? Design a TestScore class that has three integer fields, each holding a...
Java program Test Scores? Design a TestScore class that has three integer fields, each holding a test score. The class should have accessor and mutator methods for the test score fields and a method that returns the average of the test scores as a double. Test the TestScore class by writing a separate program that creates an instance of the class. The program should ask the user to enter three test scores, which should be stored in the TestScore object....
/*Design and code and test a class MaxMin that has the following properties * two integer...
/*Design and code and test a class MaxMin that has the following properties * two integer member variables, min and max where min is smaller or equal than max at all times * A default constructor that sets both min and max to 0 * A constructor that accepts one integer and sets both min and max to that integer * A constructor that accepts two integers and sets min the smallest and max the largest * * Setters and...
Write in C++: create a Doubly Linked List class that holds a struct with an integer...
Write in C++: create a Doubly Linked List class that holds a struct with an integer and a string. It must have append, insert, remove, find, and clear.
Design a class that holds the following data regarding a music album: artist, title, number of...
Design a class that holds the following data regarding a music album: artist, title, number of tracks, and year released. Write appropriate accessor and mutator methods. Also, write a program that creates three instances of the class. Each instance will hold information about a different music album. Make sure to display all of the information for all three albums to the screen in an organized manner. **Using python**
DUE IN TWO HOURS ASAP PLEASE!!! Given the following specification, design a class diagram using PlantUML....
DUE IN TWO HOURS ASAP PLEASE!!! Given the following specification, design a class diagram using PlantUML. To design the class diagram, use abstract (10 points), static (10 points), package (20 points ), namespace (20 points ), association (20 points ), and generalization (20 points ) on PlantUML Specification: A school has a principal, many students, and many teachers. Each of these persons has a name, birthdate, and may borrow and return books. The book class must contain a title, abstract,...
/*Design and code a class Calculator that has the following * tow integer member variables, num1...
/*Design and code a class Calculator that has the following * tow integer member variables, num1 and num2. * - a method to display the sum of the two integers * - a method to display the product * - a method to display the difference * - a method to display the quotient * - a method to display the modulo (num1%num2) * - a method toString() to return num1 and num2 in a string * - Test your...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT