Complete course registration system + bonus features

This commit is contained in:
2026-04-20 22:49:19 +03:30
parent 8ddd529c85
commit a1877297b9
3 changed files with 152 additions and 20 deletions
+33 -8
View File
@@ -21,19 +21,44 @@ public class Student {
}
public boolean addCourse(Course c) {
// TODO: Register the student in the course if capacity allows
// Return true if registration was successful, otherwise false
return false;
if (registeredCourses.contains(c)){
System.out.println("You have already registered in this course!"+"\n");
return (false);
} else if (registeredCourses.size()== 2){
System.out.println("You have reached the maximum number of allowed courses!"+"\n");
return (false);
}
else if (c.getCapacity()>0){
registeredCourses.add(c);
c.reduceCapacity();
return (true);
}else{
System.out.println("Registration was not successful!"+"\n"+"This course has no capacity left."+"\n");
return (false);
}
}
public boolean dropCourse(Course c) {
// TODO: Remove the course from the student's list
// Restore the course capacity if removal was successful
// Return true if the course was dropped, otherwise false
return false;
if (registeredCourses.contains(c)){
registeredCourses.remove(c);
c.increaseCapacity();
return (true);
}else{
System.out.println("Course drop failed!"+"\n"+"You are not registered for this course."+"\n");
return (false);
}
}
public void showRegisteredCourses() {
// TODO: Print all registered courses
if(registeredCourses.size()==0){
System.out.println(Main.st.getName() + "hasn't registered for any course."+"\n");
}
else {
for (int i = 0; i <= registeredCourses.size() - 1; i++) {
System.out.println(registeredCourses.get(i).getCourseName() + "(" + registeredCourses.get(i).getCourseCode() + ")" + "\n");
}
}
}
}