complete the Student file
This commit is contained in:
@@ -21,19 +21,26 @@ public class Student {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean addCourse(Course c) {
|
public boolean addCourse(Course c) {
|
||||||
// TODO: Register the student in the course if capacity allows
|
if (c.getCapacity() > 0 ) {
|
||||||
// Return true if registration was successful, otherwise false
|
registeredCourses.add(c);
|
||||||
|
c.reduceCapacity();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean dropCourse(Course c) {
|
public boolean dropCourse(Course c) {
|
||||||
// TODO: Remove the course from the student's list
|
if (registeredCourses.contains(c)) {
|
||||||
// Restore the course capacity if removal was successful
|
registeredCourses.remove(c);
|
||||||
// Return true if the course was dropped, otherwise false
|
c.increaseCapacity();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showRegisteredCourses() {
|
public void showRegisteredCourses() {
|
||||||
// TODO: Print all registered courses
|
for (Course c : registeredCourses) {
|
||||||
|
System.out.println(c);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user