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