Design a class called ItemToPurchase. <Please solve this in PYTHON> This class h
ID: 3773814 • Letter: D
Question
Design a class called ItemToPurchase. <Please solve this in PYTHON>
This class has the following attributes: item_name, item_price, and item_quanity
The ItemToPurchase class should have methods to return the current values of these attributes. In addition, this class has a method get_item_cost to
return the cost of this item (which is the product of item_price and item_quantity)
Design a class called Customer.
This class has the following attributes: customer_name, shopping_date, and shopping_cart. The shopping_cart attribute is a list of ItemToPurchase
objects.
The Customer class should have methods to get values of the name and date attributes, to add items into the shopping, and to remove items from the
shopping cart. Item removal should be done based on item name; that is, the item_remove method takes item_name as a parameter, searches an item
using the given item_name, and removes the found item from the shopping cart.
The Customer class also has a method for checking out, which should display the following information:
custoerm name, shopping date, a list of purchased items with item_name, item_quanity, and item_price, and the total cost of all the items in the
shopping cart.
In the main function, the program should create a Customer object, then ask the user to enter how many items the customer will purchase and provide
the name, price, and quantity for each item. The program adds all the items to the shopping cart. Then the program asks the user to enter the number of
items to remove from the shopping cart and provide names for these items. The program removes these items from the shopping cart. Then the
program performs check out function for the customer to display the customer name, shopping date, a list of purchased items, and the total cost.
The following is a sample output of the program:
Enter Customer Name: Mark Smith
Enter Shopping Date: November 2016
How many items does the customer want add into shopping cart? 5
Item #1
Item Name: Bottle Water
Item Price: 1.5
Item Quantity: 20
Item #2
Item Name: Chips
Item Price: 3.5
Item Quantity: 6
Item #3
Item Name: Soda
Item Price: 4.0
Item Quantity: 10
Item #4
Item Name: Coffe
Item Price: 6.5
Item Quantity: 3
Item #5
Item Name: Tea
Item Price: 5.5
Item Quantity: 4
How many items does the customer want to remove from the shopping cart? 2
Item name for removing: Soda
Soda has been removed from shopping cart.
Item name for removing: Tea
Tea has been removed from shopping cart.
Checking out
Customer Name: Mark Smith
Shopping Date: November 2016
20 Bottle Water @ $1.5
6 Chips @ $3.5
3 Coffe @ $6.5
Total Amount: $70.5
Explanation / Answer
class ItemToPurchase:
def __init__(self, name, price):
self.name = name
self.price = price
def getPrice(self):
return self.price
def getName(self):
return self.name
class ItemToPurchase:
def_init_(self,item_name,item_price,item_quantity):
self.item_name = item_name
self.item_price = item_price
self.item_quantity = item_quantity
def get_item_cost(self,item_price,item_quantity):
cost = item_price * item_quantity
return cost
class Customer(ItemToPurchase):
def __init__(self, list,cust_name,shopping_date,shopping_cart):
self.list = []
self.cust_name = cust_name
self.shopping_date = shopping_date
self.shopping_cart = shopping_cart
def addItem(self, item):
self.list.append(self.list)
def getTotal(self):
total = 0
for item in self.list:
ItemToPurchase.name, ItemToPurchase.price = item
total = total + ItemToPurchase.price
def getNumItems(self):
count = 0
print('Item Name : ',%ItemToPurchase.name)
print('Item Name : ',%ItemToPurchase.quantity)
for c in range(self.list):
count = self.list + 1
return count
def removeItem(self, ItemToPurchase.item_name)
if(name == ItemToPurchase.name)
self.list = self.list-1
else
print ("No item Found")
def checkOut (self):
total = 0
for i in self.items:
price = i[1]
total += price
return total
def show(self):
z = (str(self.ItemToPurchase.name))
print(z)
self1 =("$")+(str(ItemToPrice.price))
print(self1)
def main():
c = Cusotmer()
print('Enter Customer name',%c.cust_name)
print('Enter Shopping Date',%c.shopping_date)
print('How many items does customer want to add into shopping cart',%num)
for num in range (num--)
c.addItem()
print "How many items does the cusotmer want to remove from the shopping cart"
c.removeItem()
print "Shopping Date : ",%c.shopping_date
c.show()
main()
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.