From 1c54896277885e8777e8d72c64c49bb96185fb2c Mon Sep 17 00:00:00 2001 From: Fateme Azizi Date: Mon, 20 Apr 2026 19:09:04 +0330 Subject: [PATCH] complete Cource class --- src/CourseRegistrationStarter/Student.java | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/CourseRegistrationStarter/Student.java b/src/CourseRegistrationStarter/Student.java index 02c11d8..85dcfff 100644 --- a/src/CourseRegistrationStarter/Student.java +++ b/src/CourseRegistrationStarter/Student.java @@ -21,19 +21,29 @@ 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(c.getCapacity() > 0) { + registeredCourses.add(c); + c.reduceCapacity(); + return true; + } 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(); + return true; + } return false; } public void showRegisteredCourses() { - // TODO: Print all registered courses + + for(int i=0 ; i < registeredCourses.size() ; i++) { + System.out.print(registeredCourses.get(i).getCourseName()); + System.out.print(" "); + System.out.println(registeredCourses.get(i).getCourseCode()); + } } } \ No newline at end of file