-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay12.java
65 lines (57 loc) · 2.06 KB
/
Day12.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import java.util.Arrays;
public class Day12 {
static class Person {
protected String firstName;
protected String lastName;
protected int idNumber;
// Constructor
Person(String firstName, String lastName, int identification){
this.firstName = firstName;
this.lastName = lastName;
this.idNumber = identification;
}
// Print person data
public void printPerson(){
System.out.println(
"Name: " + lastName + ", " + firstName
+ "\nID: " + idNumber);
}
}
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.
*/
Student(String firstName, String lastName, int id, int[] testScores) {
super(firstName, lastName, id);
this.testScores = testScores;
}
/*
* Method Name: calculate
* @return A character denoting the grade.
*/
public Character calculate() {
double averageMarks = average(this.testScores);
if (averageMarks >= 90 && averageMarks <= 100) {
return 'O';
} else if (averageMarks >= 80 && averageMarks < 90) {
return 'E';
} else if (averageMarks >= 70 && averageMarks < 80) {
return 'A';
} else if (averageMarks >= 55 && averageMarks < 70) {
return 'P';
} else if (averageMarks >= 40 && averageMarks < 55) {
return 'D';
}
return 'T';
}
private double average(int[] array) {
return Arrays.stream(array).asDoubleStream().sum() / array.length;
}
}
}