Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Topping:
- def init(self, topping_type: str, weight: float):
- self._topping_type = topping_type
- self._weight = weight
- def get_topping_type(self):
- return self._topping_type
- def set_topping_type(self, value):
- if self._topping_type == "":
- raise ValueError("The topping type cannot be an empty string")
- else:
- self._topping_type = value
- def get_weight(self):
- return self._weight
- def set_weight(self, value):
- if self._weight <= 0:
- raise ValueError("The weight cannot be less or equal to zero")
- else:
- self._weight = value
- class Dough:
- def init(self, flour_type: str, baking_technique: str, weight: float):
- self._flour_type = flour_type
- self._baking_technique = baking_technique
- self._weight = weight
- def get_flour_type(self):
- return self._flour_type
- def set_flour_type(self, value):
- if self._flour_type == "":
- raise ValueError("The flour type cannot be an empty string")
- else:
- self._flour_type = value
- def get_baking_technique(self):
- return self._baking_technique
- def set_baking_technique(self, value):
- if self._baking_technique == "":
- raise ValueError("The baking technique cannot be an empty string")
- else:
- self._baking_technique = value
- def get_weight(self):
- return self._weight
- def set_weight(self, value):
- if self._weight <= 0:
- raise ValueError("The weight cannot be less or equal to zero")
- else:
- self._weight = value
- class Pizza:
- def init(self, name: str, dough: Dough, toppings_capacity: int, toppings: dict):
- self._name = name
- self._dough = dough
- self._toppings_capacity = toppings_capacity
- self._toppings = toppings
- def get_name(self):
- return self._name
- def set_name(self, value):
- if self._flour_type == "":
- raise ValueError("The name cannot be an empty string")
- else:
- self._name = value
- def get_dough(self):
- return self._dough
- def set_dough(self, value):
- if self._dough is None:
- raise ValueError("You should add dough to the pizza")
- else:
- self._dough = value
- def get_toppings_capacity(self):
- return self._toppings_capacity
- def set_toppings_capacity(self, value):
- if self._toppings_capacity <= 0:
- raise ValueError("The topping's capacity cannot be less or equal to zero")
- else:
- self._toppings_capacity = value
- def add_topping(self, topping: Topping):
- sum_of_toppings = sum(self._toppings.values())
- topping_type_to_add = topping.get_topping_type()
- topping_weight_to_add = topping.get_weight()
- if sum_of_toppings + topping.weight > self._toppings_capacity:
- raise ValueError("Not enough space for another topping")
- if topping_type_to_add not in self._toppings:
- self._toppings[topping_type_to_add] = 0
- self._toppings[topping_type_to_add] = topping_weight_to_add
- def calculate_total_weight(self):
- return sum(self._toppings.values()) + self._dough.get_weight()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement