|
| 1 | +from project.animal import Animal |
| 2 | +from project.worker import Worker |
| 3 | + |
| 4 | + |
| 5 | +class Zoo: |
| 6 | + |
| 7 | + def __init__(self, name, budget, animal_capacity, workers_capacity): |
| 8 | + self.name = name |
| 9 | + self.__budget = budget |
| 10 | + self.__animal_capacity = animal_capacity |
| 11 | + self.__workers_capacity = workers_capacity |
| 12 | + self.animals = [] |
| 13 | + self.workers = [] |
| 14 | + |
| 15 | + def add_animal(self, animal: Animal, price): |
| 16 | + if self.__budget < price: |
| 17 | + return "Not enough budget" |
| 18 | + if self.__animal_capacity == len(self.animals): |
| 19 | + return "Not enough space for animal" |
| 20 | + |
| 21 | + self.animals.append(animal) |
| 22 | + self.__budget -= price |
| 23 | + |
| 24 | + return f"{animal.name} the {animal.__class__.__name__} added to the zoo" |
| 25 | + |
| 26 | + def hire_worker(self, worker: Worker): |
| 27 | + if self.__workers_capacity == len(self.workers): |
| 28 | + return "Not enough space for worker" |
| 29 | + |
| 30 | + self.workers.append(worker) |
| 31 | + |
| 32 | + return f"{worker.name} the {worker.__class__.__name__} hired successfully" |
| 33 | + |
| 34 | + def fire_worker(self, worker_name): |
| 35 | + try: |
| 36 | + worker = next(filter(lambda w: w.name == worker_name, self.workers)) |
| 37 | + except StopIteration: |
| 38 | + return f"There is no {worker_name} in the zoo" |
| 39 | + |
| 40 | + self.workers.remove(worker) |
| 41 | + |
| 42 | + return f"{worker_name} fired successfully" |
| 43 | + |
| 44 | + def pay_workers(self): |
| 45 | + salaries = sum(w.salary for w in self.workers) |
| 46 | + |
| 47 | + if self.__budget < salaries: |
| 48 | + return "You have no budget to pay your workers. They are unhappy" |
| 49 | + |
| 50 | + self.__budget -= salaries |
| 51 | + |
| 52 | + return f"You payed your workers. They are happy. Budget left: {self.__budget}" |
| 53 | + |
| 54 | + def tend_animals(self): |
| 55 | + animals_cost = sum(a.money_for_care for a in self.animals) |
| 56 | + |
| 57 | + if self.__budget < animals_cost: |
| 58 | + return "You have no budget to tend the animals. They are unhappy." |
| 59 | + |
| 60 | + self.__budget -= animals_cost |
| 61 | + |
| 62 | + return f"You tended all the animals. They are happy. Budget left: {self.__budget}" |
| 63 | + |
| 64 | + def profit(self, amount): |
| 65 | + self.__budget += amount |
| 66 | + |
| 67 | + def animals_status(self): |
| 68 | + lions = list(filter(lambda a: a.__class__.__name__ == "Lion", self.animals)) |
| 69 | + tigers = list(filter(lambda a: a.__class__.__name__ == "Tiger", self.animals)) |
| 70 | + cheetahs = list(filter(lambda a: a.__class__.__name__ == "Cheetah", self.animals)) |
| 71 | + |
| 72 | + result = [ |
| 73 | + f"You have {len(self.animals)} animals", |
| 74 | + f"----- {len(lions)} Lions:", |
| 75 | + ] |
| 76 | + result.extend(lions) |
| 77 | + |
| 78 | + result.append(f"----- {len(tigers)} Tigers:") |
| 79 | + result.extend(tigers) |
| 80 | + |
| 81 | + result.append(f"----- {len(cheetahs)} Cheetahs:") |
| 82 | + result.extend(cheetahs) |
| 83 | + |
| 84 | + return "\n".join(str(x) for x in result) |
| 85 | + |
| 86 | + def workers_status(self): |
| 87 | + info = {"Keeper": [], "Caretaker": [], "Vet": []} |
| 88 | + [info[w.__class__.__name__].append(str(w)) for w in self.workers] |
| 89 | + |
| 90 | + result = [ |
| 91 | + f"You have {len(self.workers)} workers", |
| 92 | + f"----- {len(info['Keeper'])} Keepers:", |
| 93 | + *info['Keeper'], |
| 94 | + f"----- {len(info['Caretaker'])} Caretakers:", |
| 95 | + *info['Caretaker'], |
| 96 | + f"----- {len(info['Vet'])} Vets:", |
| 97 | + *info['Vet'], |
| 98 | + ] |
| 99 | + |
| 100 | + return "\n".join(result) |
| 101 | + |
0 commit comments