-
Notifications
You must be signed in to change notification settings - Fork 0
/
Person.html
166 lines (149 loc) · 4.23 KB
/
Person.html
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="description" content="Object Oriented JavaScript " />
<meta name="keywords" content="HTML, JavaScript" />
<meta name="author" content="A.Safarji" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Object Oriented JavaScript-github</title>
</head>
<body>
<script type="text/javascript">
class Prsons {
#address;
#name;
constructor(name, address) {
this.#name = name;
this.#address = address;
}
get Name() {
return this.#name;
}
get Address() {
return this.#address;
}
set Address(address) {
this.#address = address;
}
set Name(name) {
this.#name = name;
}
toString() {
return "(" + this.name + ", " + this.address + ")";
}
}
class Students extends Prsons {
#count = 0;
#course = [];
#grade = []; //new Array(30);
constructor(name, address) {
super(name, address);
//\this.#numCourse=numCourse;
//this.#course=course;
//this.#grade=grade;
//this.#count=0;
}
addCourseGrade(addCO, addGR) {
//var part=[];
this.#course.push(addCO);
//this.#grade=[addGR];
this.#grade.push(addGR);
this.#count++;
//if(this.#count>30)
//console.log("max courses reached");
//this.#count--;
}
PrintGrade() {
var x = "";
for (var i = 0; i < this.#grade.length; i++) {
x += this.#course[i] + ": (" + this.#grade[i] + ") \n";
}
return x;
//return "Course:" + this.#course + ", " + "Grade:" + this.#grade;
//return this.#grade[i];
}
getAvrage() {
//console.log(Object.values(this.#grade));
//return Object.values(this.#grade)/this.#count;
var total = 0;
for (var x of this.#grade) {
//return this.#grade[x]/this.#count;
total += x;
}
return total / this.#count;
}
toString() {
//return super.toString();
return super.toString() + "\n," + this.PrintGrade();
}
}
class Teacher extends Prsons {
#count = 0;
#course = [];
#grade = []; //new Array(30);
constructor(name, address) {
super(name, address);
}
addCourseGrade(addCO, addGR) {
//var part=[];
this.#course.push(addCO);
//this.#grade=[addGR];
this.#grade.push(addGR);
this.#count++;
//if(this.#count>30)
//console.log("max courses reached");
//this.#count--;
}
RemoveCourse() {
this.#course.pop();
//this.#grade=[addGR];
this.#grade.pop();
this.#count--;
console.log(this.#grade);
}
toString() {
return (
"Name,Address" +
super.toString() +
" Course: " +
this.#course +
" ," +
"Grade:" +
this.#grade
);
}
}
var zx = new Prsons();
zx.name = "safarji";
zx.address = "KSA";
//console.log(zx.toString());
var zxx = new Students();
zxx.addCourseGrade("EN", 66);
zxx.addCourseGrade("AR", 77);
zxx.addCourseGrade("CS", 88);
zxx.name = "safarji";
zxx.address = "K";
var s = new Students();
s.addCourseGrade("EN", 66);
s.addCourseGrade("AR", 77);
s.addCourseGrade("CS", 88);
s.name = "AA";
s.address = "GG";
//zxx.toString();
//console.log(zxx.PrintGrade());
console.log(zxx.toString());
console.log(s.toString());
//console.log(zxx.getAvrage());
var r = new Teacher();
r.name = "H";
r.address = "XC";
r.addCourseGrade("VV", 66);
r.addCourseGrade("dd", 88);
console.log(r.toString());
r.RemoveCourse();
console.log(r.toString());
</script>
</body>
</html>