-
Notifications
You must be signed in to change notification settings - Fork 862
/
Student.java
45 lines (38 loc) · 934 Bytes
/
Student.java
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
/**
*
* Problem Statement-
* [Inheritance](https://www.hackerrank.com/challenges/30-inheritance/problem)
*
*/
package com.javaaid.hackerrank.solutions.thirtydaysofcode;
/**
* @author Kanahaiya Gupta
*
*/
public class Student extends Person {
private int[] testScores;
Student(String firstName, String lastName, int id, int[] testScores) {
super(firstName, lastName, id);
this.testScores = testScores;
}
public char calculate() {
int sum = 0;
for (int i = 0; i < testScores.length; i++) {
sum += testScores[i];
}
int avg = (sum) / testScores.length;
if (90 <= avg && avg <= 100) {
return 'O';
} else if (80 <= avg && avg < 90) {
return 'E';
} else if (70 <= avg && avg < 80) {
return 'A';
} else if (55 <= avg && avg < 70) {
return 'P';
} else if (40 <= avg && avg < 55) {
return 'D';
} else {
return 'T';
}
}
}