Package MySTARS

Class CourseIndex

java.lang.Object
MySTARS.CourseIndex
All Implemented Interfaces:
java.io.Serializable

public final class CourseIndex
extends java.lang.Object
implements java.io.Serializable
Represents one index of a particular course/module
Since:
2020-11-11
Version:
1.0
Author:
Timothy
See Also:
Serialized Form
  • Field Summary

    Fields 
    Modifier and Type Field Description
    private int classSize
    The total enrolment of the class.
    private java.lang.String courseCode
    The course code for associated course (eg.
    private java.util.HashMap<java.lang.String,​Student> enrolledStudents
    Hashmap of currently enrolled students.
    private java.lang.String indexNumber
    The index number used to refer to this index by (eg.
    private java.util.HashMap<java.lang.Integer,​Lesson> lessons
    Hashmap of lessons, to be accessed using LessonID
    private static long serialVersionUID
    For java serializable
    private int vacancies
    The number of vacancies for this index (initially set to the maximum class size).
    private java.util.LinkedList<java.lang.String> waitlist
    The current waitlist for the index.
    private java.util.HashMap<java.lang.String,​Student> waitlistedStudents
    Hashmap of currently waitlisted students.
  • Constructor Summary

    Constructors 
    Constructor Description
    CourseIndex​(int classSize, java.lang.String courseCode, java.lang.String indexNumber)
    Constructor for course index, with no lessons at the start.
    CourseIndex​(int classSize, java.lang.String courseCode, java.lang.String indexNumber, java.util.ArrayList<Lesson> lessons)
    Constructor for the course index, and including already existing lessons inside.
  • Method Summary

    Modifier and Type Method Description
    void addLesson​(Lesson lesson)
    Add a single lesson slot to the index, if it doesn't already exist.
    void addLessons​(java.util.ArrayList<Lesson> lessons)
    Add multiple lessons to the index.
    protected void addStudent​(Student student)
    Directly adds a Student to the CourseIndex and bypasses all checks.
    void addToWaitlist​(Student student)
    Add student to the index waitlist.
    void enrollNextInWaitlist()
    Removes the student next in line in the waitlist, and enrolls object to course register.
    void enrollStudent​(Student student)
    Enrolls a specified student object into the index.
    int getClassSize()
    Returns the class size for the index.
    java.lang.String getCourseCode()
    Return the course code as a string (eg.
    java.lang.String getCourseIndex()
    Return the index number of the course index as a string (eg.
    Lesson getLesson​(java.lang.Integer lessonID)
    Returns the Lesson object based on the key value lessonID
    java.util.ArrayList<Lesson> getLessons()
    Return all the lesson slots in the index.
    java.util.ArrayList<Student> getStudents()
    Returns an array of students currently enrolled in the index.
    int getVacancies()
    Return the number of remaining vacancies.
    int getWaitlistLength()
    Return the length of the waitlist for the index.
    java.util.ArrayList<Student> getWaitlistStudents()
    Return an array of Students that are on Waitlist.
    void removeFromWaitlist​(java.lang.String username)
    Removes a specified student's username from the index waitlist.
    protected Student removeStudent​(java.lang.String username)
    Directly removes a Student from the CourseIndex.
    void setClassSize​(int classSize)
    Set the classSize
    CourseIndex simpleCopy()
    Creates a simple copy of this course index, with same parameters except for 0 vacancies.
    void unenrollStudent​(Student student)
    Removes student from the enrolled register.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • vacancies

      private int vacancies
      The number of vacancies for this index (initially set to the maximum class size).
    • classSize

      private int classSize
      The total enrolment of the class.
    • courseCode

      private java.lang.String courseCode
      The course code for associated course (eg. CZ2002)
    • indexNumber

      private java.lang.String indexNumber
      The index number used to refer to this index by (eg. 10081)
    • lessons

      private java.util.HashMap<java.lang.Integer,​Lesson> lessons
      Hashmap of lessons, to be accessed using LessonID
    • waitlist

      private java.util.LinkedList<java.lang.String> waitlist
      The current waitlist for the index. Given as a LinkedList<String> of matriculation numbers.
    • waitlistedStudents

      private java.util.HashMap<java.lang.String,​Student> waitlistedStudents
      Hashmap of currently waitlisted students. Matriculation numbers used as keys to access the respective Student objects
    • enrolledStudents

      private java.util.HashMap<java.lang.String,​Student> enrolledStudents
      Hashmap of currently enrolled students. Matriculation numbers used as keys to access the respective Student objects
    • serialVersionUID

      private static final long serialVersionUID
      For java serializable
      See Also:
      Constant Field Values
  • Constructor Details

    • CourseIndex

      public CourseIndex​(int classSize, java.lang.String courseCode, java.lang.String indexNumber)
      Constructor for course index, with no lessons at the start.
      Parameters:
      classSize - the class size for the index
      courseCode - course code of the course
      indexNumber - index number of the index
    • CourseIndex

      public CourseIndex​(int classSize, java.lang.String courseCode, java.lang.String indexNumber, java.util.ArrayList<Lesson> lessons)
      Constructor for the course index, and including already existing lessons inside.
      Parameters:
      classSize - the class size for the index
      courseCode - course code of the course
      indexNumber - index number of the index
      lessons - ArrayList of lessons to include in the index
  • Method Details

    • setClassSize

      public void setClassSize​(int classSize) throws java.lang.Exception
      Set the classSize
      Parameters:
      classSize - total enrolment of the class.
      Throws:
      java.lang.Exception - if class size is smaller than already registered students.
    • getClassSize

      public int getClassSize()
      Returns the class size for the index.
      Returns:
      class size of the index.
    • getVacancies

      public int getVacancies()
      Return the number of remaining vacancies.
      Returns:
      the number of remaining vacancies.
    • getCourseCode

      public java.lang.String getCourseCode()
      Return the course code as a string (eg. CZ2002).
      Returns:
      course code as a string.
    • getCourseIndex

      public java.lang.String getCourseIndex()
      Return the index number of the course index as a string (eg. 10081).
      Returns:
      index number of the course index.
    • addLesson

      public void addLesson​(Lesson lesson)
      Add a single lesson slot to the index, if it doesn't already exist. Lesson is added into the HashMap lessons.
      Parameters:
      lesson - lesson object to be added.
    • addLessons

      public void addLessons​(java.util.ArrayList<Lesson> lessons)
      Add multiple lessons to the index. All lessons are added into the HashMap lessons.
      Parameters:
      lessons - ArrayList containing lesson objects.
    • getLessons

      public java.util.ArrayList<Lesson> getLessons()
      Return all the lesson slots in the index.
      Returns:
      ArrayList of all lesson slots in the index.
    • getLesson

      public Lesson getLesson​(java.lang.Integer lessonID)
      Returns the Lesson object based on the key value lessonID
      Parameters:
      lessonID - the Integer identifier for a particular lesson.
      Returns:
      corresponding Lesson object.
    • getWaitlistLength

      public int getWaitlistLength()
      Return the length of the waitlist for the index.
      Returns:
      the length of the waitlist for the index.
    • getWaitlistStudents

      public java.util.ArrayList<Student> getWaitlistStudents()
      Return an array of Students that are on Waitlist.
      Returns:
      A Student array.
    • addToWaitlist

      public void addToWaitlist​(Student student)
      Add student to the index waitlist.
      Parameters:
      student - The Student to be added.
    • removeFromWaitlist

      public void removeFromWaitlist​(java.lang.String username)
      Removes a specified student's username from the index waitlist.
      Parameters:
      username - username of student to be removed.
    • getStudents

      public java.util.ArrayList<Student> getStudents()
      Returns an array of students currently enrolled in the index.
      Returns:
      array of students currently enrolled in the index.
    • enrollStudent

      public void enrollStudent​(Student student)
      Enrolls a specified student object into the index. Prints error message, and gives user choice to add to waitlist instead, if there are no remaining vacancies in the index.
      Parameters:
      student - student object to be enrolled in the index.
    • unenrollStudent

      public void unenrollStudent​(Student student)
      Removes student from the enrolled register. Prints error message to user if student is not found.
      Parameters:
      student - student object to be unenrolled.
    • enrollNextInWaitlist

      public void enrollNextInWaitlist()
      Removes the student next in line in the waitlist, and enrolls object to course register. Error messages are printed to the user if there are no vacancies in the index, or if the waitlist is empty.
    • addStudent

      protected void addStudent​(Student student)
      Directly adds a Student to the CourseIndex and bypasses all checks.
      Parameters:
      student - Student to be added to the Index.
    • removeStudent

      protected Student removeStudent​(java.lang.String username)
      Directly removes a Student from the CourseIndex.
      Parameters:
      username - Username of the Student to be removed.
      Returns:
      a Student object that was removed.
    • simpleCopy

      public CourseIndex simpleCopy()
      Creates a simple copy of this course index, with same parameters except for 0 vacancies.
      Returns:
      CourseIndex object, with same parameters except for 0 vacancies.