-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudentGradeManagement.java
More file actions
62 lines (51 loc) · 1.51 KB
/
StudentGradeManagement.java
File metadata and controls
62 lines (51 loc) · 1.51 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
import java.util.ArrayList;
import java.util.Collections;
class Student {
String name;
int id;
ArrayList<Double> grades;
Student(String name, int id) {
this.name = name;
this.id = id;
this.grades = new ArrayList<>();
}
void addGrade(double grade) {
grades.add(grade);
}
double calculateAverageGrade() {
double sum = 0;
for (double grade : grades) {
sum += grade;
}
return sum / grades.size();
}
double findHighestGrade() {
return Collections.max(grades);
}
double findLowestGrade() {
return Collections.min(grades);
}
void displayGradeReport() {
System.out.println("Student Name: " + name);
System.out.println("Student ID: " + id);
System.out.println("Grades: " + grades);
System.out.println("Average Grade: " + calculateAverageGrade());
System.out.println("Highest Grade: " + findHighestGrade());
System.out.println("Lowest Grade: " + findLowestGrade());
}
}
public class Main {
public static void main(String[] args) {
Student student1 = new Student("John", 101);
student1.addGrade(85);
student1.addGrade(92);
student1.addGrade(78);
Student student2 = new Student("Jane", 102);
student2.addGrade(88);
student2.addGrade(94);
student2.addGrade(82);
student1.displayGradeReport();
System.out.println();
student2.displayGradeReport();
}
}