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 usingLesson
IDprivate static long
serialVersionUID
For java serializableprivate 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 aStudent
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 theLesson
object 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.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 ofStudent
s 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 aStudent
from the CourseIndex.void
setClassSize(int classSize)
Set the classSizeCourseIndex
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.
-
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 usingLesson
ID -
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 theLesson
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
Return an array ofStudent
s 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 aStudent
to the CourseIndex and bypasses all checks.- Parameters:
student
-Student
to be added to the Index.
-
removeStudent
Directly removes aStudent
from 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.
-