I need this program to buy and sell items from a list. the list needs to display similar to below and have a menu for user to select options from:
ID No. Name Price Stock
1 Apples $2.50 4
Choice:
Buy - 1
Sell - 2
Quit - 0
*Needs to be done using object-oriented technique.
class Catalog(object):
pick = showMenu()
if pick == 0:
break
elif pick == 1:
sellItem()
elif pick == 2:
buyItem()
else:
print "Invalid selection"
def showMenu():
pick = int(raw_input('''
Enter selection:
0 - Quit
1 - Sell Item
2 - Buy Item
Selection : ''' ))
def __init__(self, ID, name, price, stock ):
self.ID = ID
self.name = name
self.price = price
self.stock = []
def buyStock(self, howMany):
self.stock += howMany
def sellStock(self, howMany):
if howMany <= self.stock:
self.stock -= howMany
return True
else:
return False
def __str__(self):
return str(self.ID) + " " + self.name + " $%0.2f " %self.price + str(self.stock)
class Products(object):
def __init__(self, item_catalog):
self.item_list = item_catalog
self.catalog = {1:["Bread", 1.50, 10 ], 2:["Cheese", 5.00, 5], 3:["Apples", 2.50,12]}
for name in self.item_list:
self.catalog[name] = Item(name)
I've tried and failed at this too... :(