From e2650ab295cb9a2cd4edb13206db8356127386bd Mon Sep 17 00:00:00 2001 From: HadiSharifi Date: Wed, 22 Apr 2026 23:42:58 +0330 Subject: [PATCH 1/4] complete the RegistrationSystem file --- .idea/misc.xml | 2 +- .../RegistrationSystem.java | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index a20905f..ea71d50 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/src/CourseRegistrationStarter/RegistrationSystem.java b/src/CourseRegistrationStarter/RegistrationSystem.java index 934f222..bbf98dd 100644 --- a/src/CourseRegistrationStarter/RegistrationSystem.java +++ b/src/CourseRegistrationStarter/RegistrationSystem.java @@ -9,16 +9,21 @@ public class RegistrationSystem { } public void addCourseToSystem(Course c) { - // TODO: Add the course to the system + courses.add(c); } public Course findCourseByCode(String code) { - // TODO: Search for a course by course code - // Return the matching course if found, otherwise return null + for (Course c : courses) { + if (c.getCourseCode().equals(code)) { + return c; + } + } return null; } public void showAllCourses() { - // TODO: Print all courses in the system + for (Course c : courses) { + System.out.println(c); + } } } -- 2.54.0 From 6c77d61577a38baac0a85877ae9c0dccebf494df Mon Sep 17 00:00:00 2001 From: HadiSharifi Date: Wed, 22 Apr 2026 23:51:33 +0330 Subject: [PATCH 2/4] complete the Student file --- src/CourseRegistrationStarter/Student.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/CourseRegistrationStarter/Student.java b/src/CourseRegistrationStarter/Student.java index 02c11d8..98044d3 100644 --- a/src/CourseRegistrationStarter/Student.java +++ b/src/CourseRegistrationStarter/Student.java @@ -21,19 +21,26 @@ 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.contains(c)) { + registeredCourses.remove(c); + c.increaseCapacity(); + return true; + } return false; } public void showRegisteredCourses() { - // TODO: Print all registered courses + for (Course c : registeredCourses) { + System.out.println(c); + } } } \ No newline at end of file -- 2.54.0 From da642f987ae00796f0e7509557e64dff5c97fdac Mon Sep 17 00:00:00 2001 From: HadiSharifi Date: Thu, 23 Apr 2026 00:00:43 +0330 Subject: [PATCH 3/4] complete Bonus methods --- .../RegistrationSystem.java | 15 ++++++++++++++- src/CourseRegistrationStarter/Student.java | 10 ++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/CourseRegistrationStarter/RegistrationSystem.java b/src/CourseRegistrationStarter/RegistrationSystem.java index bbf98dd..8b7fe46 100644 --- a/src/CourseRegistrationStarter/RegistrationSystem.java +++ b/src/CourseRegistrationStarter/RegistrationSystem.java @@ -9,7 +9,12 @@ public class RegistrationSystem { } public void addCourseToSystem(Course c) { - courses.add(c); + if (courses.contains(c)) { + return; + } + else { + courses.add(c); + } } public Course findCourseByCode(String code) { @@ -26,4 +31,12 @@ public class RegistrationSystem { System.out.println(c); } } + public Course findCourseByName(String name) { + for (Course c : courses) { + if (c.getCourseName().equals(name)) { + return c; + } + } + return null; + } } diff --git a/src/CourseRegistrationStarter/Student.java b/src/CourseRegistrationStarter/Student.java index 98044d3..6ffdc9a 100644 --- a/src/CourseRegistrationStarter/Student.java +++ b/src/CourseRegistrationStarter/Student.java @@ -21,10 +21,12 @@ public class Student { } public boolean addCourse(Course c) { - if (c.getCapacity() > 0 ) { - registeredCourses.add(c); - c.reduceCapacity(); - return true; + if (registeredCourses.size() <= 3) { + if (c.getCapacity() > 0) { + registeredCourses.add(c); + c.reduceCapacity(); + return true; + } } return false; } -- 2.54.0 From 8d37b845f9b3c7ecb670e4a42f79bb8460d5b2a0 Mon Sep 17 00:00:00 2001 From: HadiSharifi Date: Thu, 23 Apr 2026 00:51:26 +0330 Subject: [PATCH 4/4] complete Main file --- src/CourseRegistrationStarter/Main.java | 15 +++++++++++++++ .../RegistrationSystem.java | 2 +- src/CourseRegistrationStarter/Student.java | 2 +- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/CourseRegistrationStarter/Main.java b/src/CourseRegistrationStarter/Main.java index 8f06373..a53a683 100644 --- a/src/CourseRegistrationStarter/Main.java +++ b/src/CourseRegistrationStarter/Main.java @@ -4,11 +4,26 @@ public class Main { public static void main(String[] args) { // TODO: // 1. Create at least 3 courses + Course AdvancedProgramming = new Course("Advanced Programming","123",2); + Course DataStructures = new Course("Data Structures","456",3); + Course DatabaseSystems = new Course("Database Systems","789",2); // 2. Create 1 student + Student Hadi = new Student("Hadi","40033037"); // 3. Create a registration system + RegistrationSystem CS = new RegistrationSystem(); // 4. Add courses to the system + CS.addCourseToSystem(AdvancedProgramming); + CS.addCourseToSystem(DataStructures); + CS.addCourseToSystem(DatabaseSystems); // 5. Register the student in some courses + Hadi.addCourse(DataStructures); + Hadi.addCourse(DatabaseSystems); + Hadi.addCourse(AdvancedProgramming); // 6. Drop one course + Hadi.dropCourse(DataStructures); // 7. Print the final registered course list + Hadi.showRegisteredCourses(); + CS.showAllCourses(); + } } diff --git a/src/CourseRegistrationStarter/RegistrationSystem.java b/src/CourseRegistrationStarter/RegistrationSystem.java index 8b7fe46..165bc5d 100644 --- a/src/CourseRegistrationStarter/RegistrationSystem.java +++ b/src/CourseRegistrationStarter/RegistrationSystem.java @@ -28,7 +28,7 @@ public class RegistrationSystem { public void showAllCourses() { for (Course c : courses) { - System.out.println(c); + System.out.println(c.getCourseName()+" "+c.getCourseCode()+" "+c.getCapacity()); } } public Course findCourseByName(String name) { diff --git a/src/CourseRegistrationStarter/Student.java b/src/CourseRegistrationStarter/Student.java index 6ffdc9a..5a0ca75 100644 --- a/src/CourseRegistrationStarter/Student.java +++ b/src/CourseRegistrationStarter/Student.java @@ -42,7 +42,7 @@ public class Student { public void showRegisteredCourses() { for (Course c : registeredCourses) { - System.out.println(c); + System.out.println(c.getCourseName()+" "+c.getCourseCode()); } } } \ No newline at end of file -- 2.54.0