student registered corses in oop

This commit is contained in:
2026-04-20 18:40:03 +03:30
parent 8ddd529c85
commit 4110d28298
3 changed files with 54 additions and 18 deletions
+24 -6
View File
@@ -21,19 +21,37 @@ 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
if(registeredCourses.contains(c)){
System.out.println("Studend registered in this corse!");
return false;
}
if(c.reduceCapacity()){
registeredCourses.add(c);
System.out.println("corse added:" + c.getCourseName());
return true;
}
System.out.println("corse is full");
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
if(registeredCourses.remove(c)){
c.increaseCapacity();
System.out.println("corse dropped :" + c.getCourseName());
return true;
}
System.out.println("studend is not registered in this corse!");
return false;
}
public void showRegisteredCourses() {
// TODO: Print all registered courses
System.out.println("registered corses for " + name + ":");
if(registeredCourses.isEmpty()){
System.out.println("no corses registered");
return;
}
for(Course c : registeredCourses){
System.out.println("- " + c.getCourseName() + "/" + c.getCourseCode());
}
}
}