Skip to content

Commit f4b4153

Browse files
committed
re order exercises
1 parent 8a20614 commit f4b4153

File tree

1 file changed

+61
-64
lines changed

1 file changed

+61
-64
lines changed

03-chapter-List.js

Lines changed: 61 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// List data structure class example in ES6
2-
// ###################################
31
class List {
42
constructor(dataStore = [], listSize = 0, pos = 0) {
53
this.dataStore = dataStore;
@@ -93,7 +91,7 @@ class List {
9391
}
9492
}
9593

96-
// Class People for Excercise 1 and 2
94+
// Class GenericList for Excercise 1 and 2
9795
// ###################################
9896
class GenericList extends List {
9997
constructor(dataStore, listSize) {
@@ -139,67 +137,6 @@ class GenericList extends List {
139137
}
140138
}
141139

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-
203140

204141
// Implementations
205142
// ###################################
@@ -258,7 +195,27 @@ list6.insertSmallerThan(3);
258195
list6.insertSmallerThan(0);
259196
console.log(list6.toString());
260197

198+
// Class People for Excercise 3
261199
// ###################################
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+
262219
/*
263220
3.- Create a Person class that stores a person’s name and their gender.
264221
Create a list of at least 10 Person objects. Write a function that displays
@@ -291,7 +248,47 @@ peopleList.insert(p10,p3.name);
291248
peopleList.displayByGender('male');
292249
peopleList.displayByGender('female');
293250

251+
252+
// Class People for Excercise 4
294253
// ###################################
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+
295292
/*
296293
4.- Modify the video-rental kiosk program so that when a movie is checked out it
297294
is added to a list of rented movies. Display this list whenever a customer

0 commit comments

Comments
 (0)