In: Computer Science
Python 3
Your program will have 2 classes:
A) RetailItem Class
Write a class named RetailItem that holds data about an item in retail store.
Attributes: The class should store following data in attributes:
>item_Name
> Price
Methods:
> RetailItem class’s __init__ method should accept an argument for each attribute.
> RetailItem class should also have accessor and mutator methods for each attribute
B) MainMenu Class
Attributes: The class should store following data in attributes:
> List of RetailItem Objects: Inventory
Methods:
> createInventory(): method to create three RetailItem Objects store in list Inventory and populate following data in them
Item_Name | Price |
Milk | 10 |
Bread | 20 |
Egg | 15 |
> DisplayItems(): method to display items of Inventory List
>Method name main(): createInventory and display Inventory
Note: While copying the code from Chegg Windows, adds some extra characters and it disturbs the indentation as well. Please be cautious while copying. Please refer the screen shot of the code for indentation of the code.
Code:
===== RetailItem.py===
#retail item class
class RetailItem:
#constructor to set name and price
def __init__(self,item_name,price):
self.item_name = item_name
self.Price = price
#accessors
def get_item_name(self):
return self.item_name
def get_Price(self):
return self.Price
#mutators
def set_item_name(self,name):
self.item_name = name
def set_Price(self, price):
self.Price = price
=== MainMenu.py====
from RetailItem import RetailItem
#main menu class
class MainMenu:
#declare a list of retail item for RetailItem
Inventory =[]
#createInventory method to create 3 objects of retail item and add it to list
def createInventory(self):
self.Inventory.append(RetailItem("Milk",10))
self.Inventory.append(RetailItem("Bread",20))
self.Inventory.append(RetailItem("Egg",15))
#display all the items
def DisplayItems(self):
for item in self.Inventory:
print("Item name :{}, Price: {}".format(item.get_item_name(),item.get_Price()))
#main method to create inventory and display item
def main(self):
self.createInventory()
self.DisplayItems()
#call main method
if __name__ == '__main__':
mainDisplay = MainMenu()
mainDisplay.main()
=============screen shot of code for indentation========
Output: