-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudent.java
More file actions
40 lines (34 loc) · 1.12 KB
/
Student.java
File metadata and controls
40 lines (34 loc) · 1.12 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
import java.util.ArrayList;
import java.util.List;
public class Student {
private String studentID;
private String name;
private List<Course> registeredCourses;
public Student(String studentID, String name) {
this.studentID = studentID;
this.name = name;
this.registeredCourses = new ArrayList<>();
}
// Getters and Setters
public String getStudentID() { return studentID; }
public String getName() { return name; }
public List<Course> getRegisteredCourses() { return registeredCourses; }
public boolean registerCourse(Course course) {
if (!registeredCourses.contains(course) && course.enrollStudent()) {
registeredCourses.add(course);
return true;
}
return false;
}
public boolean dropCourse(Course course) {
if (registeredCourses.remove(course)) {
course.dropStudent();
return true;
}
return false;
}
@Override
public String toString() {
return "Student ID: " + studentID + ", Name: " + name + ", Registered Courses: " + registeredCourses.size();
}
}