Python 3.6.1 Programming Homework

Create a Python program that acts as a grocery store shopping cart. Add input validation where you see fit, use good program design, comments and form.

1. Create a base class named GroceryItem.  This class should 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

– an abstract method isPerishable

Save this class in GroceryItem.py.

 

2. Create a subclass Perishable that inherits from GroceryItem.  This class should contain:

– an __ init__ method that passes a name and price to GroceryItem

– an implementation of isPerishable that returns True

Save this class in Perishable.py.

 

3. Create a subclass NonPerishable that inherits from GroceryItem.  This class should contain:

– an __ init__ method that passes a name and price to GroceryItem

– an implementation of isPerishable that returns False

Save this class in NonPerishable.py.

 

4. Create a main program that continuously shows the user a menu for manipulating GroceryItems into a list.  Your menu should allow the user to:

– add an item to their cart

– show all items in the car

– checkout and exit

 

Each menu choice should be handled in a separate method to do the work, such as a method to createGroceryItem, printCart, and checkout, making your main pretty simple.  Show the user a menu continuously until they choose to checkout.

createGroceryItem should do the job of prompting the user for the name and price of a grocery item.  Also ask the user if this item is perishable or not, then creating the appropriate Perishable or NonPerishable object and appending it to your list of GroceryItems.

printCart should print all the elements in the GroceryItem list.

checkout should output some kind of store receipt to the user, then exit the program.  It should show all the items in the cart with their price, sales tax, then the total bill amount.  Separate the items in the receipt by perishable vs non-perishable.

Save this class in Final.py.

 

THIS IS AN EXAMPLE:

 

1: Add item to cart

2: Show cart

3: Checkout

Please choose a menu item: 1

 

Please enter grocery item name and price: milk 1.99

Is your item perishable? y/n y

 

1: Add item to cart

2: Show cart

3: Checkout

Please choose a menu item: 1

 

Please enter grocery item name and price: papertowel 3.99

Is your item perishable? y/n n

 

1: Add item to cart

2: Show cart

3: Checkout

Please choose a menu item: 2

 

milk: $1.99

papertowel: $3.99

 

1: Add item to cart

2: Show cart

3: Checkout

Please choose a menu item: 3

 

Order from us and get better grades. We are the service you have been looking for.