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 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...
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...
Write a C++ program which prompts the user to enter an integer value, stores it into...
Write a C++ program which prompts the user to enter an integer value, stores it into a variable called ‘num’, evaluates the following expressions and displays results on screen. num+5, num-3, (num+3) – 2, ((num+5)*2 / (num+3)) For performing addition and subtraction, you are allowed to use ONLY the increment and decrement operators (both prefixing and postfixing are allowed). You must remember that using increment/decrement operators changes the original value of a number. Indent your code and include comments for...
C++ Design a class named TermPaper that holds an author's name, the subject of the paper,...
C++ Design a class named TermPaper that holds an author's name, the subject of the paper, and an assigned letter grade. Include methods to set the values for each data field and display the values for each data field. Create the class diagram and write the pseudocode that defines the class. Pseudocode help please
Design an Inventory class that can hold information for an item in a retail store’s inventory.
C++! Becareful following the test case.7. Inventory ClassDesign an Inventory class that can hold information for an item in a retail store’s inventory.The class should have the following private member variables.Variable Name   DescriptionitemNumber   An int that holds the item’s number.quantity               An int that holds the quantity of the item on hand.cost    A double that holds the wholesale per-unit cost of the itemThe class should have the following public member functionsMember Function               Descriptiondefault constructor             Sets all the member variables...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT