-
Notifications
You must be signed in to change notification settings - Fork 2
task_2_flat #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
task_2_flat #4
Changes from all commits
b64a802
49e2b96
6fe3d91
19dc5dd
4aea48d
068d237
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| class Flat: | ||
|
|
||
| def __init__(self, kitchen, bedroom, bathroom, bigbedroom, guestbedroom): | ||
| self.kitchen = kitchen | ||
| self.bedroom = bedroom | ||
| self.bathroom = bathroom | ||
| self.bigbedroom = bigbedroom | ||
| self.guestbedroom = guestbedroom | ||
|
|
||
| def print_rooms(self): | ||
| print(f'{Kitchen.TITLE, Bedroom.TITLE, Bathroom.TITLE, BigBedroom.TITLE, GuestBedroom.TITLE}') | ||
|
|
||
| def print_flat_size(self): | ||
| flat_size = self._calculate_flat_size() | ||
| print(f'Flat size: {flat_size}') | ||
|
|
||
| def print_kitchen_size(self, size): | ||
| print(f'Kitchen size: {self.kitchen.get_size()}') | ||
|
|
||
| def print_bedroom_size(self, size): | ||
| print(f'Bedroom size: {self.bedroom.get_size()}') | ||
|
|
||
| def print_bathroom_size(self, size): | ||
| print(f'Bathroom size: {self.bathroom.get_size()}') | ||
|
|
||
| def print_bigbedroom_size(self, size): | ||
| print(f'Bigbedroom size: {self.bigbedroom.get_size()}') | ||
|
|
||
| def print_guestbedroom_size(self, size): | ||
| print(f'Guestbedroom size: {self.guestbedroom.get_size()}') | ||
|
|
||
| def _calculate_flat_size(self): | ||
| return f'{self.kitchen.get_size() + self.bathroom.get_size() + self.bedroom.get_size() + self.bigbedroom.get_size() + self.guestbedroom.get_size()}' | ||
|
|
||
|
|
||
| class Room: | ||
|
|
||
| def __init__(self, size): | ||
| self.__size = size | ||
|
|
||
| def get_size(self): | ||
| return self.__size | ||
|
|
||
|
|
||
| class Kitchen(Room): | ||
This comment was marked as outdated.
Sorry, something went wrong. |
||
| TITLE = 'Kitchen' | ||
|
|
||
| def __init__(self, size): | ||
smartiqa marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| super().__init__(size) | ||
| self.__purpose = 'To eat' | ||
|
|
||
| class Bedroom(Room): | ||
| TITLE = 'Bedroom' | ||
|
|
||
| def __init__(self, size): | ||
| super().__init__(size) | ||
| self.__purpose = 'To sleep' | ||
|
|
||
| class Bathroom(Room): | ||
| TITLE = 'Bathroom' | ||
|
|
||
| def __init__(self, size): | ||
| super().__init__(size) | ||
| self.__purpose = 'To wash' | ||
|
|
||
|
|
||
| class BigBedroom(Room): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. А в чем выгода наличия классов BigBedroom и GuestBedroom, если они наследуются от Room? Ни в чем. Надо наследовать их от класса Bedroom, тогда можно унаследовать например поле __purpose - ведь хоть это разные виды спален, но все равно назначение To sleep не меняется, это все равно спальни. Плюс каждому из этих классов можно добавить свой функционал. Например, у класса BigBedroom можно не передавать в конструктор размер, а задать его внутри(ведь большой не может считаться спальня с любым размером). Например так: |
||
| TITLE = 'BigBedroom' | ||
|
|
||
| def __init__(self, size): | ||
| super().__init__(size) | ||
| self.__purpose = 'Спальня с двуспальной кроватью' | ||
|
|
||
| class GuestBedroom(Room): | ||
| TITLE = 'GuestBedroom' | ||
|
|
||
| def __init__(self, size): | ||
| super().__init__(size) | ||
| self.__purpose = 'Гостевая спальня' | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
|
|
||
| my_kitchen = Kitchen(13) | ||
|
|
||
| my_bedroom = Bedroom(18) | ||
|
|
||
| my_bathroom = Bathroom(4) | ||
|
|
||
| my_bigbedroom = BigBedroom(20) | ||
|
|
||
| my_guestbedroom = GuestBedroom(21) | ||
|
|
||
| my_flat = Flat(my_kitchen, my_bedroom, my_bathroom, my_guestbedroom, my_bigbedroom) | ||
|
|
||
| my_flat.print_rooms() | ||
| my_flat.print_flat_size() | ||
| my_flat.print_kitchen_size(my_kitchen) | ||
| my_flat.print_bedroom_size(my_bedroom) | ||
| my_flat.print_bathroom_size(my_bathroom) | ||
| my_flat.print_bigbedroom_size(my_bigbedroom) | ||
| my_flat.print_guestbedroom_size(my_guestbedroom) | ||
Uh oh!
There was an error while loading. Please reload this page.