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