Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. from MenuItem import MenuItem
  2.  
  3.  
  4. class Diner(object):
  5. STATUSES = ["seated", "ordering", "eating", "paying", "leaving"]
  6.  
  7. # Set the diner’s name attribute to the input value.
  8. # Set the diner’s order attribute to an empty list.
  9. # Set the status attribute to 0.
  10. def __init__(self, name):
  11. self.__name = name
  12. self.__order = []
  13. self.__status = 0
  14.  
  15. # Define getters and setters for all the instance attributes.
  16. def getName(self):
  17. return self.__name
  18.  
  19. def setName(self, n):
  20. self.__name = n
  21.  
  22. def getOrder(self):
  23. return self.__order
  24.  
  25. def setOrder(self, n):
  26. self.__order = n
  27.  
  28. def getStatus(self):
  29. return self.__status
  30.  
  31. def setStatus(self, n):
  32. self.__status = n
  33.  
  34. # Add the new MenuItem object to the diner’s order list.
  35. def addToOrder(self, n):
  36. self.__order.append(n)
  37.  
  38. # Increase the diner’s status by 1.
  39. def updateStatus(self):
  40. self.__status += 1
  41.  
  42. # Print a message containing all the menu items the diner ordered.
  43. def printOrder(self):
  44. print(self.__name, "ordered: ")
  45. for i in self.__order:
  46. print("-", i)
  47.  
  48. # Total up the cost of each of the menu items the diner ordered.
  49. def calculateMealCost(self):
  50. cost = 0
  51. for i in self.__order:
  52. cost += i.getPrice()
  53. cost = float(cost)
  54. return cost
  55.  
  56. # Construct a message containing the diner’s name and status.
  57. def __str__(self):
  58. msg = "Diner " + self.__name + " is currently " + Diner.STATUSES[self.__status]
  59. return msg
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement