Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # file name appliance.py
- class Appliance:
- def __init__(self, cost: float):
- self.cost = cost
- def get_monthly_expense(self):
- return self.cost * 30
- ---------------------------------------------------------------------------------------------------------------
- # file name fridge.py
- from project.appliances.appliance import Appliance
- class Fridge(Appliance):
- def __init__(self):
- super().__init__(1.2)
- ---------------------------------------------------------------------------------------------------------------
- # file name laptop.py
- from project.appliances.appliance import Appliance
- class Laptop(Appliance):
- def __init__(self):
- super().__init__(1)
- ---------------------------------------------------------------------------------------------------------------
- # file name stove.py
- from project.appliances.appliance import Appliance
- class Stove(Appliance):
- def __init__(self):
- super().__init__(0.7)
- ---------------------------------------------------------------------------------------------------------------
- # file name tv.py
- from project.appliances.appliance import Appliance
- class TV(Appliance):
- def __init__(self):
- super().__init__(1.5)
- ---------------------------------------------------------------------------------------------------------------
- # file name child.py
- class Child:
- def __init__(self, food_cost: int, *toys_cost):
- self.food_cost = food_cost # money for a day
- self.cost = 0
- for toy in toys_cost:
- self.cost += toy
- self.cost += food_cost
- ---------------------------------------------------------------------------------------------------------------
- # file name alone_old.py
- from project.rooms.room import Room
- class AloneOld(Room):
- def __init__(self, family_name: str, pension: float):
- super().__init__(family_name, pension, 1)
- self.room_cost = 10
- ---------------------------------------------------------------------------------------------------------------
- # file name alone_young.py
- from project.appliances.tv import TV
- from project.rooms.room import Room
- class AloneYoung(Room):
- def __init__(self, family_name: str, salary: float):
- super().__init__(family_name, salary, 1)
- self.room_cost = 10
- self.appliances = [TV()]
- self.calculate_expenses(self.appliances)
- ---------------------------------------------------------------------------------------------------------------
- # file name old_couple.py
- from project.appliances.fridge import Fridge
- from project.appliances.stove import Stove
- from project.appliances.tv import TV
- from project.rooms.room import Room
- class OldCouple(Room):
- def __init__(self, family_name: str, pension_one: float, pension_two: float):
- super().__init__(family_name, pension_one + pension_two, 2)
- self.room_cost = 15
- self.appliances = [TV(), Fridge(), Stove()] * 2
- self.calculate_expenses(self.appliances)
- ---------------------------------------------------------------------------------------------------------------
- # file name room.py
- from project.appliances.appliance import Appliance
- class Room:
- def __init__(self, name: str, budget: float, members_count: int):
- self.family_name = name
- self.budget = budget
- self.members_count = members_count
- self.children = []
- self.expenses = 0
- @property
- def expenses(self):
- return self.__expenses
- @expenses.setter
- def expenses(self, value):
- if value < 0:
- raise ValueError("Expenses cannot be negative")
- self.__expenses = value
- def calculate_expenses(self, *args):
- total_expenses = 0
- for elements in args:
- for el in elements:
- if isinstance(el, Appliance):
- total_expenses += el.get_monthly_expense()
- elif el.__class__.__name__ == "Child":
- total_expenses += el.cost * 30
- self.expenses = total_expenses
- ---------------------------------------------------------------------------------------------------------------
- # file name young_couple.py
- from project.appliances.fridge import Fridge
- from project.appliances.laptop import Laptop
- from project.appliances.tv import TV
- from project.rooms.room import Room
- class YoungCouple(Room):
- def __init__(self, family_name: str, salary_one: float, salary_two: float):
- super().__init__(family_name, salary_one + salary_two, 2)
- self.room_cost = 20
- self.appliances = [TV(), Fridge(), Laptop()] * 2
- self.calculate_expenses(self.appliances)
- --------------------------------------------------------------------------------------------------------------
- # file name young_couple_with_children.py
- from project.appliances.fridge import Fridge
- from project.appliances.laptop import Laptop
- from project.appliances.tv import TV
- from project.rooms.room import Room
- class YoungCoupleWithChildren(Room):
- def __init__(self, family_name: str, salary_one: float, salary_two: float, *children):
- count = 2 + len(children)
- super().__init__(family_name, salary_one + salary_two, count)
- self.room_cost = 30
- self.children = list(children)
- self.appliances = [TV(), Fridge(), Laptop()] * count
- self.calculate_expenses(self.appliances, self.children)
- ---------------------------------------------------------------------------------------------------------------
- # file name everland.py
- from project.rooms.room import Room
- class Everland:
- def __init__(self):
- self.rooms = []
- def add_room(self, room: Room):
- if room not in self.rooms:
- self.rooms.append(room)
- def get_monthly_consumptions(self):
- total_consumption = 0
- for room in self.rooms:
- total_consumption += room.expenses + room.room_cost
- return f"Monthly consumptions: {total_consumption:.2f}$."
- def pay(self):
- result = ''
- for room in self.rooms:
- if room.budget >= room.expenses:
- room.budget -= room.expenses + room.room_cost
- result += f"{room.family_name} paid {(room.expenses + room.room_cost):.2f}$ and have" \
- f" {room.budget:.2f}$ left.\n"
- else:
- self.rooms.remove(room)
- result += f"{room.family_name} does not have enough budget and must leave the hotel.\n"
- return result.strip()
- def status(self):
- all_people_in_the_hotel = sum([room.members_count for room in self.rooms])
- result = f'Total population: {all_people_in_the_hotel}\n'
- for room in self.rooms:
- result += f"{room.family_name} with {room.members_count} members. Budget: {room.budget:.2f}$," \
- f" Expenses: {room.expenses:.2f}$\n"
- if room.__class__.__name__ == "YoungCoupleWithChildren":
- child_number = 1
- for child in room.children:
- result += f"--- Child {child_number} monthly cost: {(child.cost * 30):.2f}$\n"
- child_number += 1
- if room.__class__.__name__ != "AloneOld":
- total_expenses = 0
- for appliance in room.appliances:
- total_expenses += appliance.get_monthly_expense()
- result += f"--- Appliances monthly cost: {total_expenses:.2f}$\n"
- return result.strip()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement