From 7799199b08267a88c3e692042b905abdfb34348c Mon Sep 17 00:00:00 2001 From: Matin Date: Wed, 22 Apr 2026 08:24:36 +0330 Subject: [PATCH] Complete all classes . --- .idea/.name | 1 + src/CourseRegistrationStarter/Main.java | 25 +++++++++++++++++++ .../RegistrationSystem.java | 12 +++++++++ src/CourseRegistrationStarter/Student.java | 19 ++++++++++++++ 4 files changed, 57 insertions(+) create mode 100644 .idea/.name diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..d0d677e --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +Course.java \ No newline at end of file diff --git a/src/CourseRegistrationStarter/Main.java b/src/CourseRegistrationStarter/Main.java index 8f06373..dd1b111 100644 --- a/src/CourseRegistrationStarter/Main.java +++ b/src/CourseRegistrationStarter/Main.java @@ -4,11 +4,36 @@ public class Main { public static void main(String[] args) { // TODO: // 1. Create at least 3 courses + + Course course1 = new Course("Advanced Programming" , "AP1404", 2) ; + Course course2 = new Course("Data Structures", "DS2201", 1) ; + Course course3 = new Course("Database Systems", "DB3301", 3) ; + // 2. Create 1 student + + Student student1 = new Student ("Ali", "402222001") ; + // 3. Create a registration system + + RegistrationSystem registrationSystem = new RegistrationSystem() ; + // 4. Add courses to the system + + registrationSystem.addCourseToSystem(course1) ; + registrationSystem.addCourseToSystem(course2) ; + registrationSystem.addCourseToSystem(course3) ; + // 5. Register the student in some courses + + student1.addCourse(course1) ; + student1.addCourse(course2) ; + student1.addCourse(course3) ; // 6. Drop one course + + student1.dropCourse(course2) ; // 7. Print the final registered course list + + student1.showRegisteredCourses() ; + registrationSystem.showAllCourses(); } } diff --git a/src/CourseRegistrationStarter/RegistrationSystem.java b/src/CourseRegistrationStarter/RegistrationSystem.java index 934f222..2b5b84c 100644 --- a/src/CourseRegistrationStarter/RegistrationSystem.java +++ b/src/CourseRegistrationStarter/RegistrationSystem.java @@ -10,15 +10,27 @@ 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 + for (int i = 0 ; i < courses.size() ; i++) + { + if ( courses.get(i).getCourseCode().equals(code)) + { + return courses.get(i); + } + } // Return the matching course if found, otherwise return null return null; } public void showAllCourses() { // TODO: Print all courses in the system + for (int i = 0 ; i < courses.size() ; i++) + { + System.out.println(courses.get(i).getCourseName() + " (" + courses.get(i).getCourseCode() + ") - Remaining Capacity: " + courses.get(i).getCapacity()); + } } } diff --git a/src/CourseRegistrationStarter/Student.java b/src/CourseRegistrationStarter/Student.java index 02c11d8..59b7c37 100644 --- a/src/CourseRegistrationStarter/Student.java +++ b/src/CourseRegistrationStarter/Student.java @@ -22,12 +22,26 @@ public class Student { public boolean addCourse(Course c) { // TODO: Register the student in the course if capacity allows + + if (c.getCapacity() > 0) + { + registeredCourses.add(c) ; + c.reduceCapacity() ; + return true ; + } // Return true if registration was successful, otherwise false return false; } public boolean dropCourse(Course c) { // TODO: Remove the course from the student's list + + if (registeredCourses.remove(c)) + { + c.increaseCapacity() ; + return true ; + + } // Restore the course capacity if removal was successful // Return true if the course was dropped, otherwise false return false; @@ -35,5 +49,10 @@ public class Student { public void showRegisteredCourses() { // TODO: Print all registered courses + + for(int i = 0 ; i < registeredCourses.size() ; i++) + { + System.out.println(registeredCourses.get(i).getCourseName() + " - " + registeredCourses.get(i).getCourseCode()); + } } } \ No newline at end of file