From 8f1cd0d721cf333e61637137f48ff5b074de6c17 Mon Sep 17 00:00:00 2001 From: ShayanEdalatjoo Date: Mon, 20 Apr 2026 23:15:32 +0330 Subject: [PATCH 1/2] finishing TODO parts --- src/CourseRegistrationStarter/Main.java | 21 +++++++++++++++++++ .../RegistrationSystem.java | 5 +++++ src/CourseRegistrationStarter/Student.java | 17 +++++++++++++++ 3 files changed, 43 insertions(+) diff --git a/src/CourseRegistrationStarter/Main.java b/src/CourseRegistrationStarter/Main.java index 8f06373..cc1303e 100644 --- a/src/CourseRegistrationStarter/Main.java +++ b/src/CourseRegistrationStarter/Main.java @@ -2,6 +2,27 @@ package CourseRegistrationStarter; public class Main { public static void main(String[] args) { + Course BP = new Course("Basic Programing", "1000", 5); + Course AP = new Course("Advanced Programing", "1001", 5); + Course M = new Course("Math", "1002", 5); + + Student shayan = new Student("Shayan", "404212345"); + + RegistrationSystem regSys = new RegistrationSystem(); + regSys.addCourseToSystem(AP); + regSys.addCourseToSystem(BP); + regSys.addCourseToSystem(M); + + shayan.addCourse(BP); + shayan.addCourse(AP); + shayan.addCourse(M); + + shayan.dropCourse(M); + + shayan.showRegisteredCourses(); + + + // TODO: // 1. Create at least 3 courses // 2. Create 1 student diff --git a/src/CourseRegistrationStarter/RegistrationSystem.java b/src/CourseRegistrationStarter/RegistrationSystem.java index 934f222..0b01557 100644 --- a/src/CourseRegistrationStarter/RegistrationSystem.java +++ b/src/CourseRegistrationStarter/RegistrationSystem.java @@ -9,10 +9,15 @@ public class RegistrationSystem { } public void addCourseToSystem(Course c) { + courses.add(c); // TODO: Add the course to the system } public Course findCourseByCode(String code) { + for(int i = 0; i < courses.size(); i++){ + if (courses.get(i).getCourseCode().equals(code)) + return courses.get(i); + } // TODO: Search for a course by course code // Return the matching course if found, otherwise return null return null; diff --git a/src/CourseRegistrationStarter/Student.java b/src/CourseRegistrationStarter/Student.java index 02c11d8..6424efb 100644 --- a/src/CourseRegistrationStarter/Student.java +++ b/src/CourseRegistrationStarter/Student.java @@ -21,12 +21,26 @@ public class Student { } public boolean addCourse(Course c) { + if(registeredCourses.contains(c)) + return false; + if((c.getCapacity() > 0)){ + this.registeredCourses.add(c); + c.reduceCapacity(); + return true; + } // TODO: Register the student in the course if capacity allows // Return true if registration was successful, otherwise false return false; } public boolean dropCourse(Course c) { + for(int i = 0; i < this.registeredCourses.size(); i++){ + if (this.registeredCourses.get(i) == c){ + this.registeredCourses.remove(c); + c.increaseCapacity(); + return true; + } + } // 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 @@ -34,6 +48,9 @@ public class Student { } public void showRegisteredCourses() { + for(int i = 0; i < registeredCourses.size(); i++){ + System.out.println(this.registeredCourses.get(i).getCourseName() + ", code: " + this.registeredCourses.get(i).getCourseCode()); + } // TODO: Print all registered courses } } \ No newline at end of file -- 2.54.0 From 1e03e35f9cf6d314078063508f6bfbf0629686d2 Mon Sep 17 00:00:00 2001 From: ShayanEdalatjoo Date: Sat, 23 May 2026 09:48:51 +0330 Subject: [PATCH 2/2] Fixing reported bugs. --- src/CourseRegistrationStarter/Main.java | 11 ----------- .../RegistrationSystem.java | 12 ++++++------ src/CourseRegistrationStarter/Student.java | 10 ++-------- 3 files changed, 8 insertions(+), 25 deletions(-) diff --git a/src/CourseRegistrationStarter/Main.java b/src/CourseRegistrationStarter/Main.java index cc1303e..8f2e559 100644 --- a/src/CourseRegistrationStarter/Main.java +++ b/src/CourseRegistrationStarter/Main.java @@ -20,16 +20,5 @@ public class Main { shayan.dropCourse(M); shayan.showRegisteredCourses(); - - - - // 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 } } diff --git a/src/CourseRegistrationStarter/RegistrationSystem.java b/src/CourseRegistrationStarter/RegistrationSystem.java index 0b01557..3eb1244 100644 --- a/src/CourseRegistrationStarter/RegistrationSystem.java +++ b/src/CourseRegistrationStarter/RegistrationSystem.java @@ -10,20 +10,20 @@ public class RegistrationSystem { public void addCourseToSystem(Course c) { courses.add(c); - // TODO: Add the course to the system } public Course findCourseByCode(String code) { - for(int i = 0; i < courses.size(); i++){ + for (int i = 0; i < courses.size(); i++) if (courses.get(i).getCourseCode().equals(code)) return courses.get(i); - } - // TODO: Search for a course by course code - // Return the matching course if found, otherwise return null return null; } public void showAllCourses() { - // TODO: Print all courses in the system + for (Course course : this.courses) { + System.out.println("----------------------------------------------"); + System.out.printf("Course Name: %s| Course ID: %s | Capacity %d\n", course.getCourseName(), course.getCourseCode(), course.getCapacity()); + System.out.println("----------------------------------------------"); + } } } diff --git a/src/CourseRegistrationStarter/Student.java b/src/CourseRegistrationStarter/Student.java index 6424efb..925eb13 100644 --- a/src/CourseRegistrationStarter/Student.java +++ b/src/CourseRegistrationStarter/Student.java @@ -28,22 +28,17 @@ public class Student { c.reduceCapacity(); return true; } - // TODO: Register the student in the course if capacity allows - // Return true if registration was successful, otherwise false return false; } public boolean dropCourse(Course c) { for(int i = 0; i < this.registeredCourses.size(); i++){ - if (this.registeredCourses.get(i) == c){ - this.registeredCourses.remove(c); + if (this.registeredCourses.get(i).getCourseCode().equals(c.getCourseCode())){ + this.registeredCourses.remove(i); c.increaseCapacity(); return true; } } - // 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; } @@ -51,6 +46,5 @@ public class Student { for(int i = 0; i < registeredCourses.size(); i++){ System.out.println(this.registeredCourses.get(i).getCourseName() + ", code: " + this.registeredCourses.get(i).getCourseCode()); } - // TODO: Print all registered courses } } \ No newline at end of file -- 2.54.0