-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathStudent.java
More file actions
38 lines (33 loc) · 914 Bytes
/
Student.java
File metadata and controls
38 lines (33 loc) · 914 Bytes
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
package udacityAdvanced;
import java.util.List;
import java.util.Objects;
public class Student {
private int score;
private List<Student> students;
public Student(int score) {
this.score = score;
}
public Student(List<Student> students) {
this.students = students;
}
public int getScore() {
return score;
}
public int imperativeTopScore(List<Student> students) {
int topScore = 0;
for (Student s : students) {
if (s == null) continue;
topScore = Math.max (topScore, s.getScore());
}
System.out.println(topScore);
return topScore;
}
// OR
public int functionalTopScore(List<Student> students) {
return students.stream()
.filter(Objects::nonNull)
.mapToInt(Student::getScore)
.max()
.orElse(0);
}
}