oop Multi class

Need help with this code… class ‘Baggage’. will track inventory items added to or removed from it. Inventory items will be represented by inventory item objects created using the ‘InventoryItem’ class. When an attempt is made to add an inventory item to a Baggage object, the number of items in the Baggage object is compared with maximum capacity and allowable items. If space is left and the item is allowed, the item is added, otherwise, the class returns a response indicating failure with a short reason why.

Bellow is what I have so far.

Don't use plagiarized sources. Get Your Custom Essay on
oop Multi class
Just from $13/Page
Order Essay

class Baggage:

# Constructor – sets initial values for all object attributes.

def __init__(self, capacity=5, inventory=[], allow_items=()):

self.inventory = []

self.capacity = 5

self.allow_items = (

“Pen”,

“Pook”,

“Coat”,

“Umbrella”,

“Gloves”,

“Jacket”,

“Food”,

“Wallet”,

“Keys”,

“Laptop”,

“Phone”,

“Chapstick”,

“Spectacles”,

“Calculator”,

)

# Displays all items contained in a Baggage object

def print_item(self):

print(“\n”.join([str(n) for n in self.inventory]))

# Adds an item object to the Baggage object after checking that the mx capacity has not been reached (i.e. 5 items)

def add_item(self, item_object):

if len(self.inventory) <= self.capacity:

if item_object.__str__() in self.allow_items:

self.inventory.append(item_object)

print(item_object.__str__(), “has been added!!”)

return True

else: # lif item_object.__str__() not in self.allow_items:

print(item_object.__str__(), “Item is restricted from list”)

else:

print(“Reached max capacity”)

return False

# Checks of an item is in the Baggage object

def has_item(self, item_object):

for n in self.inventory:

if item_object.__str__() == n.inventory:

return True

return False

# Removes an item from the Baggage after checking its presence using has_item method

def remove_item(self, item_object):

if item_object.__str__() in self.inventory:

self.inventory.remove(item_object)

print(item_object.__str__(), ” has been removed”)

return True

else:

print(“Item not found!!”)

return False

 

class InventoryItem:

def __init__(self, item_name):

self.item_name = item_name

def __str__(self):

return “:”.join([str(self.item_name)])

 

It1 = InventoryItem(“Umbrella”)

It2 = InventoryItem(“Coat”)

It3 = InventoryItem(“Book”)

It4 = InventoryItem(“Pen”)

It5 = InventoryItem(“Cap”)

backpack = Baggage([It1, It2], 3)

backpack.print_item()

backpack.remove_item(It5)

backpack.print_item()

satche1 = Baggage([It2, It3], 4)

satche1.print_item()

satche1.remove_item(It5)

satche1.print_item()

Still struggling to complete your homework?
Get instant homework help from our expert academic writers!