Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.23 KB | None | 0 0
  1. ''' Lab 6 Question 4 '''
  2. import tkinter as tk
  3. import tkinter.ttk as ttk
  4. import tkinter.scrolledtext as stxt
  5.  
  6. class Soup:
  7. def __init__(self, code, name, price):
  8. self._code = code
  9. self._name = name
  10. self._price = price
  11. @property
  12. def code(self):
  13. return self._code
  14. @property
  15. def name(self):
  16. return self._name
  17. @property
  18. def price(self):
  19. return self._price
  20. def __str__(self):
  21. return f"{self._code} {self._name} ${self._price}"
  22.  
  23. #########################################################################
  24. class SoupStoreException(Exception):
  25. def __init__(self, errMesg):
  26. super().__init__(errMesg)
  27. ######################################################################### '''
  28. class Store:
  29. def __init__(self):
  30. self._soups = {}
  31. self._soups['C'] = [Soup('C', 'Clam Chowder', 9.9), 40]
  32. self._soups['M'] = [Soup('M', 'Mushroom', 7.9), 30]
  33. self._soups['T'] = [Soup('T', 'Tomato', 5.9), 20]
  34. self._soups['P'] = [Soup('P', 'Pumpkin', 5.9), 10]
  35. self._soups['O'] = [Soup('O', 'Oxtail', 9.9), 50]
  36.  
  37. def purchase(self, code, qty):
  38. if code not in self._soups.keys():
  39. raise SoupStoreException("Invalid soup code " + code)
  40. soupChosen = self._soups[code]
  41. servings = soupChosen[1]
  42. if servings < qty:
  43. raise SoupStoreException("Insufficient stock")
  44. # No error, go ahead with updating the servings
  45. soupChosen[1] -= qty
  46. mesg = f"{str(soupChosen[0])} remaining {soupChosen[1]}"
  47. return mesg
  48.  
  49. def replenish(self, code, qty):
  50. if code not in self._soups.keys():
  51. raise SoupStoreException("Invalid soup code " + code)
  52. soupChosen = self._soups[code]
  53. servings = soupChosen[1]
  54. if servings + qty > 50:
  55. raise SoupStoreException("Over stock")
  56. # No error, proceeding with updating
  57. soupChosen[1] += qty
  58. mesg = f"{str(soupChosen[0])} remaining {soupChosen[1]}"
  59. return mesg
  60.  
  61. def getAvailableSoups(self):
  62. codeList = list(self._soups.keys())
  63. codeList.sort()
  64. availableSoups = []
  65. for code in codeList:
  66. if self._soups[code][1] > 0:
  67. availableSoups.append(self._soups[code][0])
  68.  
  69. return availableSoups
  70.  
  71. def getReplSoups(self):
  72. codeList = list(self._soups.keys())
  73. codeList.sort()
  74. replSoups = []
  75. for code in codeList:
  76. if self._soups[code][1] < 50:
  77. replSoups.append(self._soups[code][0])
  78.  
  79. return replSoups
  80.  
  81. #################################################################
  82. class SlurpSoupsApp:
  83. def __init__(self):
  84. self._store = Store()
  85. self.createGUI()
  86.  
  87. def createGUI(self):
  88. self._win = tk.Tk()
  89. self._win.title("Slurp Soups")
  90.  
  91. inputFrame = tk.Frame(self._win)
  92. inputFrame.pack()
  93.  
  94.  
  95. def run(self):
  96. self._win.mainloop()
  97. #################################################################
  98. def main():
  99. myApp = SlurpSoupsApp()
  100. myApp.run()
  101.  
  102. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement