|
1 |
| -// List data structure class example in ES6 |
2 |
| -// ################################### |
3 | 1 | class List {
|
4 | 2 | constructor(dataStore = [], listSize = 0, pos = 0) {
|
5 | 3 | this.dataStore = dataStore;
|
@@ -93,7 +91,7 @@ class List {
|
93 | 91 | }
|
94 | 92 | }
|
95 | 93 |
|
96 |
| -// Class People for Excercise 1 and 2 |
| 94 | +// Class GenericList for Excercise 1 and 2 |
97 | 95 | // ###################################
|
98 | 96 | class GenericList extends List {
|
99 | 97 | constructor(dataStore, listSize) {
|
@@ -139,67 +137,6 @@ class GenericList extends List {
|
139 | 137 | }
|
140 | 138 | }
|
141 | 139 |
|
142 |
| -// Class People for Excercise 3 |
143 |
| -// ################################### |
144 |
| -class People { |
145 |
| - constructor(name = 'generic Doe', gender = 'generic') { |
146 |
| - this.name = name; |
147 |
| - this.gender = gender; |
148 |
| - } |
149 |
| -} |
150 |
| - |
151 |
| -class PeopleList extends List { |
152 |
| - |
153 |
| - displayByGender(gender) { |
154 |
| - console.log(`Displaying only people who has the gender: ${gender}`); |
155 |
| - this.dataStore.forEach((person, counter) => { |
156 |
| - if(person.gender === gender){ |
157 |
| - console.log(`${counter + 1}.- ${person.name}`); |
158 |
| - } |
159 |
| - }); |
160 |
| - } |
161 |
| -} |
162 |
| - |
163 |
| -// Class People for Excercise 4 |
164 |
| -// ################################### |
165 |
| - |
166 |
| -class Customer { |
167 |
| - constructor(name = 'Juan Colorado', movie = 'Monarcas Morelia Movie') { |
168 |
| - this.name = name; |
169 |
| - this.movie = movie; |
170 |
| - } |
171 |
| -} |
172 |
| - |
173 |
| -class MovieStore extends List { |
174 |
| - |
175 |
| - constructor(rentedList = new List()) { |
176 |
| - super(); |
177 |
| - this.rentedList = rentedList; |
178 |
| - } |
179 |
| - |
180 |
| - checkOut(name, movie, customerList) { |
181 |
| - if(this.contains(movie)) { |
182 |
| - const c = new Customer(name, movie); |
183 |
| - customerList.append(c); |
184 |
| - this.remove(movie); |
185 |
| - this.rentedList.append(movie); |
186 |
| - console.log('\nMovies rented: '); |
187 |
| - this.rentedList.displayList(); |
188 |
| - } else { |
189 |
| - console.log(`\n${movie} is not available to rent or is already rented`); |
190 |
| - } |
191 |
| - } |
192 |
| - |
193 |
| - checkIn(movie, customer, customerList) { |
194 |
| - if(this.rentedList.contains(movie)) { |
195 |
| - this.rentedList.remove(movie); |
196 |
| - this.append(movie); |
197 |
| - // customerList.remove(customer.name); |
198 |
| - } |
199 |
| - } |
200 |
| - |
201 |
| -} |
202 |
| - |
203 | 140 |
|
204 | 141 | // Implementations
|
205 | 142 | // ###################################
|
@@ -258,7 +195,27 @@ list6.insertSmallerThan(3);
|
258 | 195 | list6.insertSmallerThan(0);
|
259 | 196 | console.log(list6.toString());
|
260 | 197 |
|
| 198 | +// Class People for Excercise 3 |
261 | 199 | // ###################################
|
| 200 | +class People { |
| 201 | + constructor(name = 'generic Doe', gender = 'generic') { |
| 202 | + this.name = name; |
| 203 | + this.gender = gender; |
| 204 | + } |
| 205 | +} |
| 206 | + |
| 207 | +class PeopleList extends List { |
| 208 | + |
| 209 | + displayByGender(gender) { |
| 210 | + console.log(`Displaying only people who has the gender: ${gender}`); |
| 211 | + this.dataStore.forEach((person, counter) => { |
| 212 | + if(person.gender === gender){ |
| 213 | + console.log(`${counter + 1}.- ${person.name}`); |
| 214 | + } |
| 215 | + }); |
| 216 | + } |
| 217 | +} |
| 218 | + |
262 | 219 | /*
|
263 | 220 | 3.- Create a Person class that stores a person’s name and their gender.
|
264 | 221 | Create a list of at least 10 Person objects. Write a function that displays
|
@@ -291,7 +248,47 @@ peopleList.insert(p10,p3.name);
|
291 | 248 | peopleList.displayByGender('male');
|
292 | 249 | peopleList.displayByGender('female');
|
293 | 250 |
|
| 251 | + |
| 252 | +// Class People for Excercise 4 |
294 | 253 | // ###################################
|
| 254 | + |
| 255 | +class Customer { |
| 256 | + constructor(name = 'Juan Colorado', movie = 'Monarcas Morelia Movie') { |
| 257 | + this.name = name; |
| 258 | + this.movie = movie; |
| 259 | + } |
| 260 | +} |
| 261 | + |
| 262 | +class MovieStore extends List { |
| 263 | + |
| 264 | + constructor(rentedList = new List()) { |
| 265 | + super(); |
| 266 | + this.rentedList = rentedList; |
| 267 | + } |
| 268 | + |
| 269 | + checkOut(name, movie, customerList) { |
| 270 | + if(this.contains(movie)) { |
| 271 | + const c = new Customer(name, movie); |
| 272 | + customerList.append(c); |
| 273 | + this.remove(movie); |
| 274 | + this.rentedList.append(movie); |
| 275 | + console.log('\nMovies rented: '); |
| 276 | + this.rentedList.displayList(); |
| 277 | + } else { |
| 278 | + console.log(`\n${movie} is not available to rent or is already rented`); |
| 279 | + } |
| 280 | + } |
| 281 | + |
| 282 | + checkIn(movie, customer, customerList) { |
| 283 | + if(this.rentedList.contains(movie)) { |
| 284 | + this.rentedList.remove(movie); |
| 285 | + this.append(movie); |
| 286 | + // customerList.remove(customer.name); |
| 287 | + } |
| 288 | + } |
| 289 | + |
| 290 | +} |
| 291 | + |
295 | 292 | /*
|
296 | 293 | 4.- Modify the video-rental kiosk program so that when a movie is checked out it
|
297 | 294 | is added to a list of rented movies. Display this list whenever a customer
|
|
0 commit comments