-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStudent.js
66 lines (57 loc) · 1.87 KB
/
Student.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Inheritance
import {Person} from "./Person.js";
import {Phone} from "./Phone.js";
export class Student extends Person {
parentPhone;
tutor;
constructor(name, DOB, gender, city, school, stream, data = {phone: "-", parentPhone: null, tutor: null}) {
super(name, DOB, gender, city, school);
this.stream = stream;
// in line
[this.phone, this.parentPhone, this.tutor] = [data.phone, data.parentPhone, data.tutor];
}
// Encapsulation
getId() {
return this.id;
}
setID(id) {
this.id = id;
}
schoolYear() {
if (this.calculateAge() === 18) {
return `is in the Second Year of A/L`;
} else if (this.calculateAge() < 18 && this.calculateAge() > 16) {
return `is in the First Year of O/L`;
} else if (this.calculateAge() > 18) {
return `has already left the School`;
} else {
return `is a primary student`;
}
}
bio() {
let gen;
if (this.getGender() === 'female') {
gen = 'She';
} else {
gen = 'He';
}
return `${this.name} is born in ${this.getDOB()}.
<br> ${gen} lives in ${this.city}.
<br> ${gen} is ${this.calculateAge()} years old.
<br> ${gen} studies in ${this.school} and ${gen} ${this.schoolYear()}.
<br> Student ID of ${this.name} is ${this.getId()}.`;
};
// Notes, results, requests, etc...
citation(message) {
if (this.phone) {
return Phone.sms(this.phone, message);
}
throw new Error(`Sorry, we have not the phone of the student ${this.name} !!!`);
}
parentCitation(message) {
if (this.parentPhone) {
Phone.sms(this.parentPhone, message);
}
throw new Error(`Sorry, we have not the parent phone of the student ${this.name} !!!`);
}
}