From 1c54896277885e8777e8d72c64c49bb96185fb2c Mon Sep 17 00:00:00 2001 From: Fateme Azizi Date: Mon, 20 Apr 2026 19:09:04 +0330 Subject: [PATCH 1/6] 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 -- 2.54.0 From a4245b41a67b88a6edb2ad3815d09e0cd20130d9 Mon Sep 17 00:00:00 2001 From: Fateme Azizi Date: Mon, 20 Apr 2026 19:28:39 +0330 Subject: [PATCH 2/6] complete RegistrationSystem class --- .../RegistrationSystem.java | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/CourseRegistrationStarter/RegistrationSystem.java b/src/CourseRegistrationStarter/RegistrationSystem.java index 934f222..7013732 100644 --- a/src/CourseRegistrationStarter/RegistrationSystem.java +++ b/src/CourseRegistrationStarter/RegistrationSystem.java @@ -9,16 +9,32 @@ public class RegistrationSystem { } public void addCourseToSystem(Course c) { - // TODO: Add the course to the system + + for (int i=0 ; i < courses.size() ; i++) { + + if(courses.get(i).getCourseCode().equals(c.getCourseCode())) { + return; + } + } + + 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(int i=0 ; i < courses.size() ; i++) { + if(courses.get(i).getCourseCode().equals(code)) { + return courses.get(i); + } + } return null; } public void showAllCourses() { - // TODO: Print all courses in the system + for(int i=0 ; i < courses.size() ; i++) { + System.out.print("Course " + i+1 + ": "); + System.out.println(courses.get(i).getCourseName() + " " + courses.get(i).getCourseCode()); + } } } -- 2.54.0 From dc4a0631777410412b48f18fdfe3b2f5efa971aa Mon Sep 17 00:00:00 2001 From: Fateme Azizi Date: Mon, 20 Apr 2026 19:56:32 +0330 Subject: [PATCH 3/6] complete Main.java --- src/CourseRegistrationStarter/Main.java | 28 ++++++++++++++++++------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/CourseRegistrationStarter/Main.java b/src/CourseRegistrationStarter/Main.java index 8f06373..2228164 100644 --- a/src/CourseRegistrationStarter/Main.java +++ b/src/CourseRegistrationStarter/Main.java @@ -2,13 +2,25 @@ package CourseRegistrationStarter; public class Main { public static void main(String[] args) { - // TODO: - // 1. Create at least 3 courses - // 2. Create 1 student - // 3. Create a registration system - // 4. Add courses to the system - // 5. Register the student in some courses - // 6. Drop one course - // 7. Print the final registered course list + + Course AdvancedProgramming = new Course("AdvancedProgramming", "AP1404", 2); + Course DataStructures = new Course("DataStructures", "DS2201", 1); + Course DatabaseSystems = new Course("DatabaseSystems", "DB3301", 3); + + Student fateme = new Student("fateme", "404222000"); + + RegistrationSystem A = new RegistrationSystem(); + + A.addCourseToSystem(AdvancedProgramming); + A.addCourseToSystem(DataStructures); + A.addCourseToSystem(DatabaseSystems); + + fateme.addCourse(AdvancedProgramming); + fateme.addCourse(DataStructures); + fateme.addCourse(DatabaseSystems); + + fateme.dropCourse(DataStructures); + + fateme.showRegisteredCourses(); } } -- 2.54.0 From e754e9bc46050f786b7f149ddc60c510e597af8b Mon Sep 17 00:00:00 2001 From: Fateme Azizi Date: Mon, 20 Apr 2026 20:07:53 +0330 Subject: [PATCH 4/6] edit showRegisteredCourses() in Student.java --- src/CourseRegistrationStarter/Student.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/CourseRegistrationStarter/Student.java b/src/CourseRegistrationStarter/Student.java index 85dcfff..b9d96fe 100644 --- a/src/CourseRegistrationStarter/Student.java +++ b/src/CourseRegistrationStarter/Student.java @@ -41,9 +41,10 @@ public class Student { public void showRegisteredCourses() { 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()); + System.out.print("Course"); + System.out.print(i+1); + System.out.print(" : " + registeredCourses.get(i).getCourseName() + " " + registeredCourses.get(i).getCourseCode()); + System.out.println(", capacity : " +registeredCourses.get(i).getCapacity()); } } } \ No newline at end of file -- 2.54.0 From 41b8d9af0a2b4968d9f3b9d8acdc059bb94f77c0 Mon Sep 17 00:00:00 2001 From: Fateme Azizi Date: Mon, 20 Apr 2026 20:12:34 +0330 Subject: [PATCH 5/6] edit showAllCourses() in RegistrationSystem.java --- src/CourseRegistrationStarter/RegistrationSystem.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/CourseRegistrationStarter/RegistrationSystem.java b/src/CourseRegistrationStarter/RegistrationSystem.java index 7013732..ba9f0c0 100644 --- a/src/CourseRegistrationStarter/RegistrationSystem.java +++ b/src/CourseRegistrationStarter/RegistrationSystem.java @@ -33,8 +33,10 @@ public class RegistrationSystem { public void showAllCourses() { for(int i=0 ; i < courses.size() ; i++) { - System.out.print("Course " + i+1 + ": "); - System.out.println(courses.get(i).getCourseName() + " " + courses.get(i).getCourseCode()); + System.out.print("Course"); + System.out.print(i+1); + System.out.print(" : " + courses.get(i).getCourseName() + " " + courses.get(i).getCourseCode()); + System.out.println(", capacity : " + courses.get(i).getCapacity()); } } } -- 2.54.0 From 66e86acde1db93829de58cadcc6038cb8995c1dd Mon Sep 17 00:00:00 2001 From: Fateme Azizi Date: Sat, 16 May 2026 13:09:33 +0330 Subject: [PATCH 6/6] implement bonus features --- src/CourseRegistrationStarter/Main.java | 2 +- .../RegistrationSystem.java | 14 +++++++++++++- src/CourseRegistrationStarter/Student.java | 15 +++++++++++---- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/CourseRegistrationStarter/Main.java b/src/CourseRegistrationStarter/Main.java index 2228164..06d7547 100644 --- a/src/CourseRegistrationStarter/Main.java +++ b/src/CourseRegistrationStarter/Main.java @@ -7,7 +7,7 @@ public class Main { Course DataStructures = new Course("DataStructures", "DS2201", 1); Course DatabaseSystems = new Course("DatabaseSystems", "DB3301", 3); - Student fateme = new Student("fateme", "404222000"); + Student fateme = new Student("fateme", "404222000", 10); RegistrationSystem A = new RegistrationSystem(); diff --git a/src/CourseRegistrationStarter/RegistrationSystem.java b/src/CourseRegistrationStarter/RegistrationSystem.java index ba9f0c0..09acb07 100644 --- a/src/CourseRegistrationStarter/RegistrationSystem.java +++ b/src/CourseRegistrationStarter/RegistrationSystem.java @@ -12,7 +12,10 @@ public class RegistrationSystem { for (int i=0 ; i < courses.size() ; i++) { - if(courses.get(i).getCourseCode().equals(c.getCourseCode())) { + if(courses.get(i).getCourseCode().equals(c.getCourseCode()) || + courses.get(i).getCourseName().equals(c.getCourseName())) { + + System.out.println("Course name or code already exists."); return; } } @@ -31,6 +34,15 @@ public class RegistrationSystem { return null; } + public Course findCourseByName(String name) { + + for(int i=0 ; i registeredCourses; + private int courseLimit; - public Student(String name, String studentId) { + public Student(String name, String studentId, int courseLimit) { this.name = name; this.studentId = studentId; this.registeredCourses = new ArrayList<>(); + this.courseLimit = courseLimit; } public String getName() { @@ -22,7 +24,7 @@ public class Student { public boolean addCourse(Course c) { - if(c.getCapacity() > 0) { + if(c.getCapacity() > 0 && registeredCourses.size() < courseLimit) { registeredCourses.add(c); c.reduceCapacity(); return true; @@ -30,6 +32,11 @@ public class Student { return false; } + public void setCourseLimit(int amount) { + if(amount>0) + courseLimit = amount; + } + public boolean dropCourse(Course c) { if (registeredCourses.remove(c)) { c.increaseCapacity(); -- 2.54.0