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 intclassSizeThe total enrolment of the class.private java.lang.StringcourseCodeThe course code for associated course (eg.private java.util.HashMap<java.lang.String,Student>enrolledStudentsHashmap of currently enrolled students.private java.lang.StringindexNumberThe index number used to refer to this index by (eg.private java.util.HashMap<java.lang.Integer,Lesson>lessonsHashmap of lessons, to be accessed usingLessonIDprivate static longserialVersionUIDFor java serializableprivate intvacanciesThe number of vacancies for this index (initially set to the maximum class size).private java.util.LinkedList<java.lang.String>waitlistThe current waitlist for the index.private java.util.HashMap<java.lang.String,Student>waitlistedStudentsHashmap 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 voidaddLesson(Lesson lesson)Add a single lesson slot to the index, if it doesn't already exist.voidaddLessons(java.util.ArrayList<Lesson> lessons)Add multiple lessons to the index.protected voidaddStudent(Student student)Directly adds aStudentto the CourseIndex and bypasses all checks.voidaddToWaitlist(Student student)Add student to the index waitlist.voidenrollNextInWaitlist()Removes the student next in line in the waitlist, and enrolls object to course register.voidenrollStudent(Student student)Enrolls a specified student object into the index.intgetClassSize()Returns the class size for the index.java.lang.StringgetCourseCode()Return the course code as a string (eg.java.lang.StringgetCourseIndex()Return the index number of the course index as a string (eg.LessongetLesson(java.lang.Integer lessonID)Returns theLessonobject based on the key value lessonIDjava.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.intgetVacancies()Return the number of remaining vacancies.intgetWaitlistLength()Return the length of the waitlist for the index.java.util.ArrayList<Student>getWaitlistStudents()Return an array ofStudents that are on Waitlist.voidremoveFromWaitlist(java.lang.String username)Removes a specified student's username from the index waitlist.protected StudentremoveStudent(java.lang.String username)Directly removes aStudentfrom the CourseIndex.voidsetClassSize(int classSize)Set the classSizeCourseIndexsimpleCopy()Creates a simple copy of this course index, with same parameters except for 0 vacancies.voidunenrollStudent(Student student)Removes student from the enrolled register.
-
Field Details
-
vacancies
private int vacanciesThe number of vacancies for this index (initially set to the maximum class size). -
classSize
private int classSizeThe total enrolment of the class. -
courseCode
private java.lang.String courseCodeThe course code for associated course (eg. CZ2002) -
indexNumber
private java.lang.String indexNumberThe index number used to refer to this index by (eg. 10081) -
lessons
Hashmap of lessons, to be accessed usingLessonID -
waitlist
private java.util.LinkedList<java.lang.String> waitlistThe current waitlist for the index. Given as aLinkedList<String>of matriculation numbers. -
waitlistedStudents
Hashmap of currently waitlisted students. Matriculation numbers used as keys to access the respective Student objects -
enrolledStudents
Hashmap of currently enrolled students. Matriculation numbers used as keys to access the respective Student objects -
serialVersionUID
private static final long serialVersionUIDFor 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 indexcourseCode- course code of the courseindexNumber- 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 indexcourseCode- course code of the courseindexNumber- index number of the indexlessons- ArrayList of lessons to include in the index
-
-
Method Details
-
setClassSize
public void setClassSize(int classSize) throws java.lang.ExceptionSet 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
Add a single lesson slot to the index, if it doesn't already exist. Lesson is added into the HashMaplessons.- Parameters:
lesson- lesson object to be added.
-
addLessons
Add multiple lessons to the index. All lessons are added into the HashMaplessons.- Parameters:
lessons- ArrayList containing lesson objects.
-
getLessons
Return all the lesson slots in the index.- Returns:
- ArrayList of all lesson slots in the index.
-
getLesson
Returns theLessonobject 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
Return an array ofStudents that are on Waitlist.- Returns:
- A Student array.
-
addToWaitlist
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
Returns an array of students currently enrolled in the index.- Returns:
- array of students currently enrolled in the index.
-
enrollStudent
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
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
Directly adds aStudentto the CourseIndex and bypasses all checks.- Parameters:
student-Studentto be added to the Index.
-
removeStudent
Directly removes aStudentfrom the 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.
-