diff --git a/src/CourseRegistrationStarter/Student.java b/src/CourseRegistrationStarter/Student.java index 02c11d8..e97d1c9 100644 --- a/src/CourseRegistrationStarter/Student.java +++ b/src/CourseRegistrationStarter/Student.java @@ -1,12 +1,15 @@ package CourseRegistrationStarter; import java.util.ArrayList; -public class Student { +public class Student +{ private String name; private String studentId; private ArrayList registeredCourses; + private int limit = 15; - public Student(String name, String studentId) { + public Student(String name, String studentId) + { this.name = name; this.studentId = studentId; this.registeredCourses = new ArrayList<>(); @@ -20,20 +23,45 @@ public class Student { return studentId; } - public boolean addCourse(Course c) { - // TODO: Register the student in the course if capacity allows - // Return true if registration was successful, otherwise false + public boolean addCourse(Course c) + { + if(registeredCourses.contains(c) || c.getCapacity() == 0) + { + return false; + } + else if(registeredCourses.size() <= limit && c.getCapacity() > 0) + { + c.reduceCapacity(); + registeredCourses.add(c); + return true; + } return false; } - public boolean dropCourse(Course c) { - // 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 + public boolean dropCourse(Course c) + { + if(registeredCourses.contains(c)) + { + registeredCourses.remove(c); + c.increaseCapacity(); + return true; + } return false; } - public void showRegisteredCourses() { - // TODO: Print all registered courses + public void showRegisteredCourses() + { + if(registeredCourses.size() > 0) + { + System.out.println("Registered Courses : "); + for(int i = 0; i < registeredCourses.size(); i++) { + Course c = registeredCourses.get(i); + System.out.println(c.getCourseName()); + } + } + else + { + System.out.println("NO COURSES !"); + } } } \ No newline at end of file