Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Python, I am working on creating a program that I though would be fun which acts

ID: 3866144 • Letter: P

Question

Python, I am working on creating a program that I though would be fun which acts as a grocery store shopping cart by creating the following:

creating a base class (GroceryItem) which will contain an __init__ method that initializes the item’s name and price, a getName method that returns the item’s name, a getPrice method that returns the item’s price, a __str__ method that returns a string representation of that GroceryItem and an abstract method isPerishable.

Then I want to create a subclass Perishable that inherits from GroceryItem which is an an __ init__ method that passes a name and price to GroceryItem and an implementation of isPerishable that returns True.

Then I want to create a subclass NonPerishable that inherits from GroceryItem which will contain an an __ init__ method that passes a name and price to GroceryItem and an implementation of isPerishable that returns False.

Then I will create a main program that continuously shows the user a menu for manipulating GroceryItems into a list which will allow the user to add an item to their cart and show all items in the car with a checkout and exit option.

Each of the menu choices should be handled in a separate method to do the work and have the menu appear continuously until the user has chosen to checkout.

The createGroceryItem should do the job of prompting the user for the name and price of a grocery item and ask them if the item is perishable or not, then creating the appropriate Perishable or NonPerishable object and appending it to the list of GroceryItems. Also printCart should print all the elements in the GroceryItem list.

checkout should output some kind of store receipt to the user which should show all of the items with their prices, sales tax and the total bill amount then exit the program. Also to have the items in the receipt sorted by perishable vs non-perishable.

mport snailcode as np import cv2 cap cv2.VideoCapture('snailcode .avi') while(cap.isOpenedO) ret, frame = cap.read() gray = cv2.cvtColor(frame, cv2. COLOR.BGR2GRAY) cv2.imshow( frame' ,gray) if cv2.waitKeyC1) & 0xFF == ord('q'): break cap, release cv2.destroyALlWindowsC print('Welcome to you shopping list') shoplist C addinput('Would you like to add something to your shopping list? Y/N while add.lowerO -- 'y': item-input('Enter your item to the list: ') shoplist.append(item) add = input('Would you like to add something to your shopping list? Y/N ') printO print('Your list in alphabetical order will be displayed below.") shoplist.sort(O for listitem in shoplist: print(listitem) Ln: 1 Col: 22

Explanation / Answer

1. Please run with Python Version > 3.0

2. Please copy all files in one folder

main.py is main programme

  GroceryItem.py GroceryItem class , Parent class

Perishable.py Perishable Class

NonPerishable.py NonPerishable class

main.py :-

-------------------------------------

from Perishable import Perishable
from NonPerishable import NonPerishable
groceryItems = []

def addItem() :
name = input('Enter name of Item')
price = float(input('Enter Price'))
perishable = int(input('Enter Perishable option 1 or 2 1.perishable 2.NonPerishable'))

if perishable == 1 :
item = Perishable(name,price)
groceryItems.append(item)
else :
item = NonPerishable(name,price)
groceryItems.append(item)

def printItems():
for item in groceryItems:
desc = item.getDescription()
print (desc)
def generateBill():
total = 0
for item in groceryItems:
total = total + item.getPrice()
print ('Total Price of Items : ' + str(total))
tax = total * 0.1
#Aisume 10% Sales Tax
print ('Sales Tax : ' + str(tax))
print ('Total Bill : ' + str(total + tax))

while 1 :
option = int(input('Enter Options : 1. Add Item 2.Print Cart 3.Check Out '))
  
if option == 1 :
  
addItem()
elif option == 2 :
printItems()
elif option == 3 :
printItems()
generateBill()
break

GroceryItem class :

----------------------------------------

class GroceryItem:
def __init__(self,name,price):
self.name = name
self.price = price
def getName(self):
return self.name
def getPrice(self):
return self.price
def getDescription(self):
return 'Name is : ' +self.name + ' and Price is : ' + str(self.price)
def isPerishable(self):
pass
  

Perishable Class :-

--------------------------------

from GroceryItem import GroceryItem
class Perishable(GroceryItem):
def __init__(self,name,price):
GroceryItem.__init__(self,name,price)
def isPerishable(self):
return true
  

Non Perishable :-

-----------------------------------

from GroceryItem import GroceryItem
class NonPerishable(GroceryItem):
def __init__(self,name,price):
GroceryItem.__init__(self,name,price)
def isPerishable(self):
return false