Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Enrolls student in course
- public void enroll(Course newCourse) {
- if (!this.isScheduleFull() && !this.hasCourse(newCourse)) { // if schedule is not full, and not already in course
- if (newCourse.addStudent(this)) { // Try to enroll. If class is not full, add student to it.
- courses[numofSC] = newCourse; // add course to student's list if enrolled
- numofSC++; // increment number of classes they are in
- } else { // Occurs only if the class the student is trying to enroll in is full
- System.out.print("Unable to enroll ");
- System.out.print(this.getStudentName());
- System.out.print(" in course ");
- System.out.print(newCourse.getCourseName());
- System.out.print(" (Course ID:");
- System.out.print(newCourse.getCourseId());
- System.out.println(") because course is full!");
- }
- } else { // Occurs if student's schedule is full or are already in course
- System.out.print("Unable to enroll ");
- System.out.print(this.getStudentName());
- System.out.print(" in course ");
- System.out.print(newCourse.getCourseName());
- System.out.print(" (Course ID:");
- System.out.print(newCourse.getCourseId());
- System.out.print(") because");
- // so we just adjust the output based on what happened
- if (this.hasCourse(newCourse)) { // already in course
- System.out.println(" student is already in this class!");
- } else { // schedule full
- System.out.println(" student's schedule is full!");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment