Login
Order Now
Support
Task on Python Class Diagram and Classes

Task on Python Class Diagram and Classes

  • 7th Jan, 2022
  • 16:05 PM

stock=dict()

class ItemAndCategory:
    def addItem(self, ID, name, category, price):
        stock[ID]=[name,category,price]

    def removeItem(self, ID):
        if ID in stock.keys():
            del stock[ID]
        else:
            print("Sorry, Item "+str(ID)+" is Not Available in The Stock!!!")

class Order:
    def __init__(self):
        self.cart=set()

    def add(self, ID):
        if ID in stock.keys():
            self.cart.add(ID)
        else:
            print("Sorry, Item "+str(ID)+" is Not Available in Our Stock!!!")

    def remove(self, ID):
        if ID in self.cart:
            self.cart.remove(ID)
        else:
            print("Sorry, Item "+str(ID)+" is Not Available in Your Cart!!!")
            


class Payment:
    def __init__(self, order, cardType):
        self.total=0
        self.cart=order.cart
        self.cardType=cardType

    def pay(self):
        for ID in self.cart:
            self.total+=stock[ID][2]
        self.showDetails()

    def showDetails(self):
        print("\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
        print("::Transaction Details::")
        print("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n")
        print("ID     Name    Category\t   Price")
        print("=======================================")
        for ID in self.cart:
            print(str(ID)+"   "+stock[ID][0]+"  "+stock[ID][1]+"  $"+str(stock[ID][2]))
        print("=======================================")
        print("\n\nNet Amount: $"+str(self.total))
        print("Payment Status: Paid (Using "+self.cardType+" Card)")  
            
    
    
class Customer:
    def __init__(self, name, phone_no, email):
        self.name=name
        self.phone=phone_no
        self.email=email
        self.order=Order()
            
    def addCart(self, itemID):
        self.order.add(itemID)

    def removeCart(self, itemID):
        self.order.remove(itemID)

    def pay(self, cardType):
        self.payment=Payment(self.order,cardType)
        self.payment.pay()

    

def main():
    stockHandler=ItemAndCategory()
    stockHandler.addItem(1001,"Laptop","Electronics",1200)
    stockHandler.addItem(1004,"Mobile","Electronics",205)
    stockHandler.addItem(2001,"T-Shirt","Apparel",8)
    stockHandler.removeItem(2001)


        
    customer1=Customer("Robert","123456","robert@hotmail.com")
    customer1.addCart(1001)
    customer1.addCart(1004)
    #customer1.removeCart(1001)
    customer1.addCart(2001)
    customer1.pay("Debit")


if __name__=="__main__":
    main()
 

Share this post

assignment helpassignment helperassignment expertsassignment writing services