Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ''' Lab 6 Question 4 '''
- import tkinter as tk
- import tkinter.ttk as ttk
- import tkinter.scrolledtext as stxt
- class Soup:
- def __init__(self, code, name, price):
- self._code = code
- self._name = name
- self._price = price
- @property
- def code(self):
- return self._code
- @property
- def name(self):
- return self._name
- @property
- def price(self):
- return self._price
- def __str__(self):
- return f"{self._code} {self._name} ${self._price}"
- #########################################################################
- class SoupStoreException(Exception):
- def __init__(self, errMesg):
- super().__init__(errMesg)
- ######################################################################### '''
- class Store:
- def __init__(self):
- self._soups = {}
- self._soups['C'] = [Soup('C', 'Clam Chowder', 9.9), 40]
- self._soups['M'] = [Soup('M', 'Mushroom', 7.9), 30]
- self._soups['T'] = [Soup('T', 'Tomato', 5.9), 20]
- self._soups['P'] = [Soup('P', 'Pumpkin', 5.9), 10]
- self._soups['O'] = [Soup('O', 'Oxtail', 9.9), 50]
- def purchase(self, code, qty):
- if code not in self._soups.keys():
- raise SoupStoreException("Invalid soup code " + code)
- soupChosen = self._soups[code]
- servings = soupChosen[1]
- if servings < qty:
- raise SoupStoreException("Insufficient stock")
- # No error, go ahead with updating the servings
- soupChosen[1] -= qty
- mesg = f"{str(soupChosen[0])} remaining {soupChosen[1]}"
- return mesg
- def replenish(self, code, qty):
- if code not in self._soups.keys():
- raise SoupStoreException("Invalid soup code " + code)
- soupChosen = self._soups[code]
- servings = soupChosen[1]
- if servings + qty > 50:
- raise SoupStoreException("Over stock")
- # No error, proceeding with updating
- soupChosen[1] += qty
- mesg = f"{str(soupChosen[0])} remaining {soupChosen[1]}"
- return mesg
- def getAvailableSoups(self):
- codeList = list(self._soups.keys())
- codeList.sort()
- availableSoups = []
- for code in codeList:
- if self._soups[code][1] > 0:
- availableSoups.append(self._soups[code][0])
- return availableSoups
- def getReplSoups(self):
- codeList = list(self._soups.keys())
- codeList.sort()
- replSoups = []
- for code in codeList:
- if self._soups[code][1] < 50:
- replSoups.append(self._soups[code][0])
- return replSoups
- #################################################################
- class SlurpSoupsApp:
- def __init__(self):
- self._store = Store()
- self.createGUI()
- def createGUI(self):
- self._win = tk.Tk()
- self._win.title("Slurp Soups")
- inputFrame = tk.Frame(self._win)
- inputFrame.pack()
- def run(self):
- self._win.mainloop()
- #################################################################
- def main():
- myApp = SlurpSoupsApp()
- myApp.run()
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement