-
Notifications
You must be signed in to change notification settings - Fork 178
/
Copy pathday 12.swift
39 lines (35 loc) · 840 Bytes
/
day 12.swift
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
// Class Student
class Student: Person {
var testScores: [Int]
// Write the Student class initializer
init(firstName: String, lastName: String, identification: Int, scores: [Int]) {
self.testScores = scores;
super.init(firstName: firstName, lastName: lastName, identification: identification);
}
// Write the calculate method
func calculate() -> String {
var average = 0;
for i in testScores {
average += i;
}
average = average / testScores.count;
if(average >= 90) {
return "O"; // Outstanding
}
else if(average >= 80) {
return "E"; // Exceeds Expectations
}
else if(average >= 70) {
return "A"; // Acceptable
}
else if(average >= 55) {
return "P"; // Poor
}
else if(average >= 40) {
return "D"; // Dreadful
}
else {
return "T"; // Troll
}
}
} // End of class Student