chriscct1

Untitled

Nov 18th, 2012
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.45 KB | None | 0 0
  1.     // Enrolls student in course
  2.     public void enroll(Course newCourse) {
  3.         if (!this.isScheduleFull() && !this.hasCourse(newCourse)) { // if schedule is not full, and not already in course
  4.             if (newCourse.addStudent(this)) { // Try to enroll. If class is not full, add student to it.
  5.                 courses[numofSC] = newCourse; // add course to student's list if enrolled
  6.                 numofSC++; // increment number of classes they are in
  7.             } else { // Occurs only if the class the student is trying to enroll in is full
  8.                 System.out.print("Unable to enroll ");
  9.                 System.out.print(this.getStudentName());
  10.                 System.out.print(" in course ");
  11.                 System.out.print(newCourse.getCourseName());
  12.                 System.out.print(" (Course ID:");
  13.                 System.out.print(newCourse.getCourseId());
  14.                 System.out.println(") because course is full!");
  15.             }
  16.         } else { // Occurs if student's schedule is full or are already in course
  17.             System.out.print("Unable to enroll ");
  18.             System.out.print(this.getStudentName());
  19.             System.out.print(" in course ");
  20.             System.out.print(newCourse.getCourseName());
  21.             System.out.print(" (Course ID:");
  22.             System.out.print(newCourse.getCourseId());
  23.             System.out.print(") because");
  24.             // so we just adjust the output based on what happened
  25.             if (this.hasCourse(newCourse)) { // already in course
  26.                 System.out.println(" student is already in this class!");
  27.             } else { // schedule full
  28.                 System.out.println(" student's schedule is full!");
  29.             }
  30.         }
  31.     }
Advertisement
Add Comment
Please, Sign In to add comment