diff --git a/src/CourseRegistrationStarter/Main.java b/src/CourseRegistrationStarter/Main.java index 06b727b..2a295bb 100644 --- a/src/CourseRegistrationStarter/Main.java +++ b/src/CourseRegistrationStarter/Main.java @@ -27,7 +27,7 @@ public class Main { student1.dropCourse(course2); // 7. Print the final registered course list - System.out.printf("%s registered courses:\n", student1.getName()); + System.out.printf("\n%s\'s registered courses:\n", student1.getName()); student1.showRegisteredCourses(); System.out.println("\nRemaining informations of courses are as follows: "); diff --git a/src/CourseRegistrationStarter/RegistrationSystem.java b/src/CourseRegistrationStarter/RegistrationSystem.java index fabedaf..402afa6 100644 --- a/src/CourseRegistrationStarter/RegistrationSystem.java +++ b/src/CourseRegistrationStarter/RegistrationSystem.java @@ -24,6 +24,15 @@ public class RegistrationSystem { return null; } + public Course findCourseByName(String name){ // search by course name + for(Course thisCourse : courses){ + if(thisCourse.getCourseName() == name){ + return thisCourse; + } + } + return null; + } + public void showAllCourses() { // TODO: Print all courses in the system System.out.println("Course Name | Course Code | Capacity"); diff --git a/src/CourseRegistrationStarter/Student.java b/src/CourseRegistrationStarter/Student.java index 6d38f7c..73e0cf0 100644 --- a/src/CourseRegistrationStarter/Student.java +++ b/src/CourseRegistrationStarter/Student.java @@ -5,6 +5,7 @@ public class Student { private String name; private String studentId; private ArrayList registeredCourses; + private int allowedCourses = 2; public Student(String name, String studentId) { this.name = name; @@ -24,11 +25,15 @@ public class Student { // TODO: Register the student in the course if capacity allows // Return true if registration was successful, otherwise false - if(registeredCourses.contains(c)){ + if(registeredCourses.contains(c)){ // Preventing duplicate course registration System.out.printf("%s is already registered for %s\n", c.getCourseName(), name); return false; } + if(registeredCourses.size() >= allowedCourses){ // Limiting the number of courses per student + System.out.printf("%s has reached his limit for registration.\n", name); + } + if(c.reduceCapacity()){ // if enough capacity, reduction happens in this line registeredCourses.add(c); System.out.printf("%s registered successfully.\n", c.getCourseName());