diff --git a/src/CourseRegistrationStarter/Main.java b/src/CourseRegistrationStarter/Main.java index 8f06373..de6db0c 100644 --- a/src/CourseRegistrationStarter/Main.java +++ b/src/CourseRegistrationStarter/Main.java @@ -3,6 +3,20 @@ package CourseRegistrationStarter; public class Main { public static void main(String[] args) { // TODO: + Course BP = new Course("Basic Programming", "BP1404", 3); + Course AP = new Course("Advanced Programming", "AP1405", 2); + Course DS = new Course("Data Structure", "DS1406", 2); + Student saeedJam = new Student("Saeed Jamali", "404222000"); + RegistrationSystem register = new RegistrationSystem(); + + register.addCourseToSystem(BP); + register.addCourseToSystem(AP); + register.addCourseToSystem(DS); + + saeedJam.addCourse(AP); + saeedJam.addCourse(DS); + saeedJam.dropCourse(DS); + saeedJam.showRegisteredCourses(); // 1. Create at least 3 courses // 2. Create 1 student // 3. Create a registration system diff --git a/src/CourseRegistrationStarter/RegistrationSystem.java b/src/CourseRegistrationStarter/RegistrationSystem.java index 934f222..1c520f0 100644 --- a/src/CourseRegistrationStarter/RegistrationSystem.java +++ b/src/CourseRegistrationStarter/RegistrationSystem.java @@ -9,16 +9,25 @@ public class RegistrationSystem { } public void addCourseToSystem(Course c) { + this.courses.add(c); // TODO: Add the course to the system } public Course findCourseByCode(String code) { + for (Course c: this.courses) { + if (c.getCourseCode().equals(code)) { + return c; + } + } // TODO: Search for a course by course code // Return the matching course if found, otherwise return null return null; } public void showAllCourses() { + for(Course c: this.courses) { + System.out.println(c.getCourseName() + ", code: " + c.getCourseCode()); + } // TODO: Print all courses in the system } } diff --git a/src/CourseRegistrationStarter/Student.java b/src/CourseRegistrationStarter/Student.java index 02c11d8..0ddc505 100644 --- a/src/CourseRegistrationStarter/Student.java +++ b/src/CourseRegistrationStarter/Student.java @@ -21,12 +21,22 @@ public class Student { } public boolean addCourse(Course c) { + if (c.getCapacity() > 0 && !this.registeredCourses.contains(c)) { + 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) { + if (this.registeredCourses.contains(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 +44,9 @@ public class Student { } public void showRegisteredCourses() { + for(Course c: this.registeredCourses) { + System.out.println(c.getCourseName() + ", code: " + c.getCourseCode()); + } // TODO: Print all registered courses } } \ No newline at end of file