-
Notifications
You must be signed in to change notification settings - Fork 1
/
classes.js
48 lines (46 loc) · 1.17 KB
/
classes.js
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
class SchoolPerson {
constructor(name, subjects) {
this.name = name;
this.subjects = subjects || [];
}
addSubject(subject) {
if (this.subjects.indexOf(subject) === -1) {
this.subjects.push(subject);
}
}
}
class Teacher extends SchoolPerson {
constructor(name, maxStudents, subjects) {
super(name, subjects);
this.maxStudents = maxStudents || 5;
this.students = [];
}
canTeach(student) {
return this.students.length < this.maxStudents && this.subjects.includes(student.subjects[0]);
}
}
class Student extends SchoolPerson {
constructor(name, subjects) {
super(name, subjects);
}
}
class School {
constructor() {
this.teachers = [];
this.students = [];
}
addStudent(student) {
this.students.push(student);
}
addTeacher(teacher) {
this.teachers.push(teacher);
}
assignStudent(student) {
for (let i = 0; i < this.teachers.length; i++) {
let teacher = this.teachers[i];
if (teacher.canTeach(student)) {
teacher.students.push(student);
}
}
}
}