Repository navigation
Expand file tree
/
Copy pathGradeTracker.java
More file actions
80 lines (54 loc) · 1.62 KB
/
Copy pathGradeTracker.java
File metadata and controls
80 lines (54 loc) · 1.62 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import java.util.ArrayList;
public class GradeTracker {
private ArrayList<Student> students;
public GradeTracker() {
students = new ArrayList<>();
}
public void addStudent(Student student) {
students.add(student);
}
public double calculateAverage() {
double total = 0;
for (Student student : students) {
total += student.getMarks();
}
return total / students.size();
}
public double findHighest() {
double highest = students.get(0).getMarks();
for (Student student : students) {
if (student.getMarks() > highest) {
highest = student.getMarks();
}
}
return highest;
}
public double findLowest() {
double lowest = students.get(0).getMarks();
for (Student student : students) {
if (student.getMarks() < lowest) {
lowest = student.getMarks();
}
}
return lowest;
}
public void displayStudents() {
System.out.println("\n----- STUDENT GRADE REPORT -----");
for (Student student : students) {
System.out.println(
"Name: " + student.getName()
+ " | Marks: " + student.getMarks()
);
}
System.out.println("--------------------------------");
System.out.println(
"Average Marks: " + calculateAverage()
);
System.out.println(
"Highest Marks: " + findHighest()
);
System.out.println(
"Lowest Marks: " + findLowest()
);
}
}