Program 11: Student-Course registration system

You will implement a system to store information about students, courses, and enrollments of students in those courses. You will make sure that students can only be enrolled into courses if some given requirements are met. To do this, you'll have to make use of the TreeMap class.

Read through the entire task before you begin.

  1. Create a class Student with the final variable int id and the other (non-final) variables Name, int totalRegisteredCreditHrs, ArrayList<String> registeredCourseIds, which may change over time. There are also constants static final int maxNumRegisteredCourses and maxRegisteredCreditHrs that are common to all students. (Use the values 2 and 4, respectively, for these two variables.) This class will have a constructor public Student(String name, int id). A suitable public String toString(), e.g. "(Justine, id=6)". The Student class should implement StudentI.java.
  2. Create a class Course with the final variables String id , and int creditHrs, and maxClassSize, and the non-final variables String name and int classSize=0 (the current number of students in the course). A constructor public Course(String name, String id, int creditHrs, int maxClassSize) and a suitable public String toString() will be needed, e.g. "(CourseName, id=CourseId, credit: 3h, maxSize: 5)". The Course class should implement the CourseI.java interface.
  3. Create a class RegistrationKey with final variables int studentId and String courseId (which refer to existing Student and Course-objects, respectively.). Let RegistrationKey implement Comparable, and provide a method compareTo that sorts registrationKeys first by the student Ids, and in case they are equal, by the course Ids.
  4. Create a class StudentCourseRegistration that implements RegistrationI.java. The class should have a private field named registrations of type TreeMap<RegistrationKey,Date> where the value in the tree is the registration date, assigned by new Date() (the current date and time). The StudentCourseRegistration should also have private fields TreeMap<Integer,Student> students (student id and Student object), TreeMap<String,Course> courses (course id and Course object). Both have to be initialized by the constructor from appropriate data files (see below). Implement the following functions:
    1. public void readStudents() to read a file students.txt, and populate students with its data. You should print an appropriate error message if the file does not exist (catch the exception), but you can assume that the file will be in the specified format (don't catch format errors).
    2. public void readCourses() to read a file courses.txt, and populate courses with its data. You should print an appropriate error message if the file does not exist (catch the exception), but you can assume that the file will be in the specified format (don't catch format errors).
    3. public void addRegistration(int studentId, String courseId) to register a student in the given course, checking for fulfilment of some requirements. Follow the algorithm outlined below:
      1. If the given studentId is unknown, throw a RegException with a message (the argument supplied to its constructor) of "UnknownStudentId".
      2. If the given courseId is unknown, throw a RegException with "UnknownCourseId".
      3. If the registration would exceed the maximum allowed number of courses for the student, throw a RegException with "ExceedingMaxNumCourses".
      4. If the registration would exceed the maximum allowed course hours for the student, throw a RegException with "ExceedingMaxCourseHours".
      5. If the registration would exceed the maximum allowed number of students for the course, throw a RegException with "ExceedingMaxNumStudents".
      6. If the requested registration is already present, throw a RegException with "ExistingRegistration".
      7. If the request passes all requirements, add the registration to registrations and update the relevant fields in both the student and the course. The RegException.java class is provided here.
  5. Test your code by calling the testRegistrations(RegistrationI src) on the tester: StudentCourseRegTester.java.
  6. Extra Credit: Extend your StudentCourseRegistration to implement the extended registration interface (RegistrationExtendedI.java) instead of the RegistrationI.java.

    At all times, you must keep data structures consistent. The courseId's in the student.registeredCourseIds, the number of students signed up for a course, and the registered credit hours for each student should be what one expects from the set of registered courses.

    1. public void unregister(int studentId,String courseId) Unregister a student from a course, or remove said student from the waiting list. If there are any students waiting to get into this course, attempt to register them. If an exception is thrown trying to register a waiting student, move on to the next waiting student.
    2. public void registerOrWait(int studentId,String courseId) Attempt to register for a course. If the only reason you can't register is because the course is full, go on a waiting list. If the studdent is already on the waiting list, throw an RegException with "AlreadyOnWaitingList."
    3. Test your new methods by calling the tester: testRegistrationsExtended(RegistrationExtendedI src) method on the StudentCourseRegTester.java.

Valid XHTML 1.0 Strict