-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay 12: Inheritance.js
90 lines (82 loc) · 2.28 KB
/
Day 12: Inheritance.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
'use strict';
var _input = '';
var _index = 0;
process.stdin.on('data', (data) => { _input += data; });
process.stdin.on('end', () => {
_input = _input.split(new RegExp('[ \n]+'));
main();
});
function read() { return _input[_index++]; }
/**** Ignore above this line. ****/
class Person {
constructor(firstName, lastName, identification) {
this.firstName = firstName;
this.lastName = lastName;
this.idNumber = identification;
}
printPerson() {
console.log(
"Name: " + this.lastName + ", " + this.firstName
+ "\nID: " + this.idNumber
)
}
}
class Student extends Person {
/*
* Class Constructor
*
* @param firstName - A string denoting the Person's first name.
* @param lastName - A string denoting the Person's last name.
* @param id - An integer denoting the Person's ID number.
* @param scores - An array of integers denoting the Person's test scores.
*/
constructor(firstName, lastName, idNumber, scores,){
super(firstName, lastName, idNumber);
this.scores = scores;
}
/*
* Method Name: calculate
* @return A character denoting the grade.
*/
calculate(){
var sum =0;
this.scores.map(s => {
sum = sum + s;
});
let average = sum / this.scores.length;
switch(true){
case (average < 40):
return "T";
break;
case (average < 55):
return "D";
break;
case (average < 70):
return "P";
break;
case (average < 80):
return "A";
break;
case average < 90:
return "E";
break;
case (average <= 100):
return "O";
break;
}
}
}
function main() {
let firstName = read()
let lastName = read()
let id = +read()
let numScores = +read()
let testScores = new Array(numScores)
for (var i = 0; i < numScores; i++) {
testScores[i] = +read()
}
let s = new Student(firstName, lastName, id, testScores)
s.printPerson()
s.calculate()
console.log('Grade: ' + s.calculate())
}