-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGradebook.java
More file actions
53 lines (46 loc) · 1.42 KB
/
Gradebook.java
File metadata and controls
53 lines (46 loc) · 1.42 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
import java.util.ArrayList;
// Class representing the Gradebook
class Gradebook {
private ArrayList<Student> students;
// Constructor
public Gradebook() {
this.students = new ArrayList<>();
}
// Add a new student
public void addStudent(String name) {
students.add(new Student(name));
}
// Find a student by name
private Student findStudent(String name) {
for (Student student : students) {
if (student.getName().equalsIgnoreCase(name)) {
return student;
}
}
return null;
}
// Add a grade to a student
public void addGradeToStudent(String name, double grade) {
Student student = findStudent(name);
if (student != null) {
student.addGrade(grade);
} else {
System.out.println("Student not found.");
}
}
// Update a grade for a student
public void updateGradeForStudent(String name, int index, double grade) {
Student student = findStudent(name);
if (student != null) {
student.updateGrade(index, grade);
} else {
System.out.println("Student not found.");
}
}
// Display all students and their grades
public void displayAllStudents() {
for (Student student : students) {
student.displayGrades();
}
}
}