-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudent.java
More file actions
39 lines (34 loc) · 837 Bytes
/
Student.java
File metadata and controls
39 lines (34 loc) · 837 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
39
import java.util.ArrayList;
public class Student {
String name;
ArrayList<Integer> grades;
public Student(String name) {
this.name = name;
this.grades = new ArrayList<>();
}
public double getAverage() {
int sum = 0;
for (int grade : grades) {
sum += grade;
}
return grades.size() == 0 ? 0 : (double) sum / grades.size();
}
public int getHighest() {
int max = Integer.MIN_VALUE;
for (int grade : grades) {
if (grade > max) {
max = grade;
}
}
return max;
}
public int getLowest() {
int min = Integer.MAX_VALUE;
for (int grade : grades) {
if (grade < min) {
min = grade;
}
}
return min;
}
}