-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInheritance.java
43 lines (40 loc) · 1.2 KB
/
Inheritance.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
/*
Problem Title: Inheritance
Problem URL: https://www.hackerrank.com/challenges/30-inheritance/problem
Max Score: 30
Score: 30
Language: Java
Category: 30 Days of Code!
*/
class Student extends Person{
private int[] testScores;
/*
* 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.
*/
public Student(String firstName, String lastName,
int studentID, int[] scores) {
super(firstName, lastName, studentID);
this.testScores = scores;
}
/*
* Method Name: calculate
* @return A character denoting the grade.
*/
public char calculate() {
int sum = 0;
for (int i = 0; i < testScores.length; ++i)
sum += testScores[i];
int avg = sum / testScores.length;
if (avg >= 90) return 'O';
if (avg >= 80) return 'E';
if (avg >= 70) return 'A';
if (avg >= 55) return 'P';
if (avg >= 40) return 'D';
else return 'T';
}
}