Advertisement
zarkoy

Untitled

Dec 1st, 2022
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.22 KB | None | 0 0
  1. class Topping:
  2. def init(self, topping_type: str, weight: float):
  3. self._topping_type = topping_type
  4. self._weight = weight
  5.  
  6. def get_topping_type(self):
  7. return self._topping_type
  8.  
  9. def set_topping_type(self, value):
  10. if self._topping_type == "":
  11. raise ValueError("The topping type cannot be an empty string")
  12. else:
  13. self._topping_type = value
  14.  
  15. def get_weight(self):
  16. return self._weight
  17.  
  18. def set_weight(self, value):
  19. if self._weight <= 0:
  20. raise ValueError("The weight cannot be less or equal to zero")
  21. else:
  22. self._weight = value
  23.  
  24. class Dough:
  25. def init(self, flour_type: str, baking_technique: str, weight: float):
  26. self._flour_type = flour_type
  27. self._baking_technique = baking_technique
  28. self._weight = weight
  29.  
  30. def get_flour_type(self):
  31. return self._flour_type
  32.  
  33. def set_flour_type(self, value):
  34. if self._flour_type == "":
  35. raise ValueError("The flour type cannot be an empty string")
  36. else:
  37. self._flour_type = value
  38.  
  39. def get_baking_technique(self):
  40. return self._baking_technique
  41.  
  42. def set_baking_technique(self, value):
  43. if self._baking_technique == "":
  44. raise ValueError("The baking technique cannot be an empty string")
  45. else:
  46. self._baking_technique = value
  47.  
  48. def get_weight(self):
  49. return self._weight
  50.  
  51. def set_weight(self, value):
  52. if self._weight <= 0:
  53. raise ValueError("The weight cannot be less or equal to zero")
  54. else:
  55. self._weight = value
  56.  
  57. class Pizza:
  58. def init(self, name: str, dough: Dough, toppings_capacity: int, toppings: dict):
  59. self._name = name
  60. self._dough = dough
  61. self._toppings_capacity = toppings_capacity
  62. self._toppings = toppings
  63.  
  64. def get_name(self):
  65. return self._name
  66.  
  67. def set_name(self, value):
  68. if self._flour_type == "":
  69. raise ValueError("The name cannot be an empty string")
  70. else:
  71. self._name = value
  72.  
  73. def get_dough(self):
  74. return self._dough
  75.  
  76. def set_dough(self, value):
  77. if self._dough is None:
  78. raise ValueError("You should add dough to the pizza")
  79. else:
  80. self._dough = value
  81.  
  82. def get_toppings_capacity(self):
  83. return self._toppings_capacity
  84.  
  85. def set_toppings_capacity(self, value):
  86. if self._toppings_capacity <= 0:
  87. raise ValueError("The topping's capacity cannot be less or equal to zero")
  88. else:
  89. self._toppings_capacity = value
  90.  
  91. def add_topping(self, topping: Topping):
  92. sum_of_toppings = sum(self._toppings.values())
  93. topping_type_to_add = topping.get_topping_type()
  94. topping_weight_to_add = topping.get_weight()
  95. if sum_of_toppings + topping.weight > self._toppings_capacity:
  96. raise ValueError("Not enough space for another topping")
  97. if topping_type_to_add not in self._toppings:
  98. self._toppings[topping_type_to_add] = 0
  99. self._toppings[topping_type_to_add] = topping_weight_to_add
  100.  
  101. def calculate_total_weight(self):
  102. return sum(self._toppings.values()) + self._dough.get_weight()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement