-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhomework-19.js
More file actions
217 lines (131 loc) · 4.18 KB
/
Copy pathhomework-19.js
File metadata and controls
217 lines (131 loc) · 4.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
// Створити та описати сутності Багатоквартирного будинку, квартири, мешканця.
// Додати можливість створювати нові будинки на певну кількість квартир.
// Не обмежувати кількість мешканців у квартирі
class Person {
name;
gender;
constructor(name, gender) {
this.name = name;
this.gender = gender;
}
getFullInfo() {
return `${this.name} (${this.gender})`
}
}
class Flat {
residents = [];
heating = 'central';
walls = 'brick';
renovation = 'new';
addPerson(person) {
this.residents.push(person);
}
showResidents() {
console.log('Residents of this flat:');
console.warn(this.residents);
}
}
class House {
flatsMax;
flatsOccupied = [];
location = 'center';
parking = 'yes';
floors = 6;
constructor(flatsMax) {
this.flatsMax = flatsMax;
}
addFlat(flat) {
if (this.flatsOccupied.length < this.flatsMax) {
this.flatsOccupied.push(flat);
return this.flatsOccupied;
}
return console.warn('house is full');
}
showOccupiedFlats() {
console.log(this.flatsOccupied);
}
}
console.log('=======persons========');
const lena = new Person('Olena', 'female');
console.log(lena.getFullInfo());
const boris = new Person('Boris', 'male');
console.log(boris.getFullInfo());
const anna = new Person('Anna', 'female');
console.log(anna.getFullInfo());
const petro = new Person('Petro', 'male');;
console.log(petro.getFullInfo());
const vlad = new Person('Vlad', 'male');;
console.log(vlad.getFullInfo());
console.log('\n\n======flats=======');
const twoRoomFlat = new Flat();
// console.log(twoRoomFlat);
twoRoomFlat.addPerson(boris);
twoRoomFlat.addPerson(anna);
twoRoomFlat.showResidents();
const threeRoomFlat = new Flat();
threeRoomFlat.addPerson(vlad);
threeRoomFlat.addPerson(lena);
threeRoomFlat.addPerson(petro);
threeRoomFlat.showResidents();
const flat1 = new Flat();
const flat2 = new Flat();
const flat3 = new Flat();
const flat4 = new Flat();
const flat5 = new Flat();
const flat6 = new Flat();
console.log('\n\n======house=======');
const isSmallHouse = new House(5);
// console.log(isSmallHouse);
const isBigHouse = new House(8);
isSmallHouse.addFlat(threeRoomFlat);
isSmallHouse.addFlat(twoRoomFlat);
isSmallHouse.addFlat(flat1);
isSmallHouse.addFlat(flat2);
isSmallHouse.addFlat(flat3);
isSmallHouse.showOccupiedFlats();
isSmallHouse.addFlat(flat4);
// class House {
// constructor(flatsOccupied, floors, resients) {
// this.flatsAll = 30;
// this.floors = floors;
// this.resients = resients;
// this.flatsOccupied = flatsOccupied;
// }
// newFlatOccupied() {
// if (this.flatsOccupied >= this.flatsAll) {
// console.warn('the house is full');
// return;
// }
// this.flatsOccupied++;
// this.resients++;
// return this;
// }
// get flats() {
// if ((this.flatsAll - this.flatsOccupied) <= 0) {
// return 'no free flats';
// }
// return `now ${this.flatsAll - this.flatsOccupied} flats are free`
// }
// }
// const house1 = new House(25, 9, 44);
// console.warn(house1);
// console.log(house1.flats);
// house1.newFlatOccupied().newFlatOccupied().newFlatOccupied().newFlatOccupied().newFlatOccupied().newFlatOccupied();
// console.log(house1);
// console.log(house1.flats);
// house1.newFlatOccupied();
// house1.newFlatOccupied();
// house1.newFlatOccupied();
// console.log(house1);
// console.log('-----------');
// const house2 = new House(40, 12, 100);
// console.log(house2);
// house2.newFlatOccupied();
// console.log(house2);
// console.log('-----------');
// const house3 = new House(10, 5, 22);
// console.log(house3);
// console.log(house3.flats);
// house3.newFlatOccupied().newFlatOccupied().newFlatOccupied().newFlatOccupied().newFlatOccupied().newFlatOccupied().newFlatOccupied().newFlatOccupied();
// console.log(house3);
// console.log(house3.flats);