Package MySTARS
Class Student
java.lang.Object
MySTARS.User
MySTARS.Student
- All Implemented Interfaces:
java.io.Serializable,java.lang.Comparable<Student>
public final class Student extends User implements java.lang.Comparable<Student>
Represents one Student
- Since:
- 2020-11-11
- Version:
- 1.0
- Author:
- Jia Hui
- See Also:
- Serialized Form
-
Field Summary
Fields Modifier and Type Field Description private java.util.HashMap<java.lang.String,Course>coursesA list of courses the student is registered under or on waitlist for.private java.lang.StringfirstNameThe student's first name.private GendergenderThe student'sGender.private java.lang.StringlastNameThe student's last name.private java.lang.StringmatricNumberThe student's unique, 9-character matriculation number.static intmaxAUsThe maximum number of AUs that a Student can take.private java.lang.StringnationalityThe student's nationality.private intregisteredAUsThe student's number of registered Academic Units.private static longserialVersionUIDThe unique ID of the class for Serialisation. -
Constructor Summary
Constructors Constructor Description Student(java.lang.String userName, java.lang.String matricNumber, java.lang.String firstName, java.lang.String lastName, java.lang.String password, Gender gender, java.lang.String nationality)The constructor with all possible parameters.Student(java.lang.String userName, java.lang.String matricNumber, java.lang.String firstName, java.lang.String lastName, Gender gender, java.lang.String nationality)The constructor with the minimum required number of parameters. -
Method Summary
Modifier and Type Method Description private voidaddAU(AU acadUnits)Adds the specified number ofAUs to the student's registered AUs.CourseStatusaddCourse(java.lang.String courseCode, java.lang.String courseIndex)Adds a course to theStudent's timetable.booleanaddCourseFromWaitlist(CourseIndex courseIndex)Registers the student from waitlist.voidchangeIndex(java.lang.String code, java.lang.String currentInd, java.lang.String newInd)Puts the student in a different index of a registered course.booleanclashes(java.lang.String courseCode, java.lang.String index)Checks if a course index of a course clashes with the student's timetable.intcompareTo(Student o)Compares this student with the specified student for order.voiddropCourse(java.lang.String courseCode)Drops a course from the student's timetable.intgetAU()Returns the student's current number of registered Academic Units (AUs).CoursegetCourse(java.lang.String courseCode)Returns aCourseobject that the Student has registered for.Course[]getCourses(CourseStatus courseStatus)Returns a list of the student's courses, based on the desired course status.java.lang.StringgetFirstName()Returns the student's first name.GendergetGender()Returns the student's gender.CourseIndex[]getIndices(CourseStatus courseStatus)Returns a list of the student's course indices, based on the desired course status.java.lang.StringgetLastName()Returns the student's last name.java.lang.StringgetMatricNumber()Returns the student's matriculation number.java.lang.StringgetNationality()Returns the student's nationality.static booleanisValidMatricNo(java.lang.String matricNo)Checks if a String can be used as a matriculation number.static booleanisValidNewMatricNo(java.lang.String matricNo)Checks if a String can be used as a new matriculation number.CourseStatusplanCourse(Course course, CourseIndex courseIndex)AddsCourses to the Student's plan.private voidremoveAU(AU acadUnits)Removes the specified number ofAUs from the student's registered AUs.protected CourseremoveCourse(java.lang.String courseCode)Directly removes aCoursefrom the courses Hashmap.CourseIndexremoveIndex(java.lang.String courseCode, java.lang.String courseIndex)Directly removes aCourseIndexfrom aCoursein the courses Hashmap.protected voidsetCourse(Course course)Directly adds aCourseto the Hashmap.voidsetIndex(java.lang.String courseCode, CourseIndex courseIndex)Directly Adds aCourseIndexto aCoursein the courses Hashmap.StudentsimpleCopy()Creates a copy of this student object with minimal information.Methods inherited from class MySTARS.User
changeAccessLevel, changePassword, checkPassword, getAccessLevel, getUsername
-
Field Details
-
serialVersionUID
private static final long serialVersionUIDThe unique ID of the class for Serialisation.- See Also:
- Constant Field Values
-
matricNumber
private java.lang.String matricNumberThe student's unique, 9-character matriculation number. -
firstName
private java.lang.String firstNameThe student's first name. -
lastName
private java.lang.String lastNameThe student's last name. -
courses
A list of courses the student is registered under or on waitlist for. -
gender
The student'sGender. -
nationality
private java.lang.String nationalityThe student's nationality. -
registeredAUs
private int registeredAUsThe student's number of registered Academic Units. -
maxAUs
public static final int maxAUsThe maximum number of AUs that a Student can take.- See Also:
- Constant Field Values
-
-
Constructor Details
-
Student
public Student(java.lang.String userName, java.lang.String matricNumber, java.lang.String firstName, java.lang.String lastName, Gender gender, java.lang.String nationality)The constructor with the minimum required number of parameters.- Parameters:
userName- the student's unique username (eg.HKIM007)matricNumber- the student's unique, 9-character matriculation numberfirstName- the student's first namelastName- the student's last namegender- the student's gendernationality- the student's nationality
-
Student
public Student(java.lang.String userName, java.lang.String matricNumber, java.lang.String firstName, java.lang.String lastName, java.lang.String password, Gender gender, java.lang.String nationality)The constructor with all possible parameters.- Parameters:
userName- the student's unique username (eg.HKIM007)matricNumber- the student's unique, 9-character matriculation numberfirstName- the student's first namelastName- the student's last namepassword- the student's password for accessing the STARS systemgender- the student's gendernationality- the student's nationality
-
-
Method Details
-
isValidMatricNo
public static boolean isValidMatricNo(java.lang.String matricNo)Checks if a String can be used as a matriculation number.- Parameters:
matricNo- the matriculation number.- Returns:
- whether the passed in value is in a valid matriculation number format.
-
isValidNewMatricNo
public static boolean isValidNewMatricNo(java.lang.String matricNo)Checks if a String can be used as a new matriculation number.- Parameters:
matricNo- the matriculation number.- Returns:
- returns whether the passed in value is in a valid matriculation number format and has not been used yet.
-
getMatricNumber
public java.lang.String getMatricNumber()Returns the student's matriculation number.- Returns:
- the student's unique matriculation number
-
getFirstName
public java.lang.String getFirstName()Returns the student's first name.- Returns:
- the student's first name
-
getLastName
public java.lang.String getLastName()Returns the student's last name.- Returns:
- the student's last name
-
getGender
Returns the student's gender.- Returns:
- the student's gender
-
getNationality
public java.lang.String getNationality()Returns the student's nationality.- Returns:
- the student's nationality
-
getCourse
Returns aCourseobject that the Student has registered for.- Parameters:
courseCode- The String value of the course.- Returns:
- A Course Object.
-
getCourses
Returns a list of the student's courses, based on the desired course status. Eg. If courseStatus = CourseStatus.REGISTERED, then only registered courses will be returned.- Parameters:
courseStatus- defines the desried course status used to filter courses- Returns:
- a list of the student's courses that have the desired course status
-
removeCourse
Directly removes aCoursefrom the courses Hashmap.- Parameters:
courseCode- The code of the course to be removed- Returns:
- a Course object that is removed from the Hashmap.
-
setCourse
Directly adds aCourseto the Hashmap.- Parameters:
course- The course to be added.
-
getIndices
Returns a list of the student's course indices, based on the desired course status. Eg. If courseStatus = CourseStatus.REGISTERED, then only registered course indices will be returned.- Parameters:
courseStatus- defines the desried course status used to filter courses.- Returns:
- a list of the student's course indices that have the desired course status.
-
getAU
public int getAU()Returns the student's current number of registered Academic Units (AUs).- Returns:
- the student's current number of registered Academic Units (AUs)
-
addAU
Adds the specified number ofAUs to the student's registered AUs.- Parameters:
acadUnits- the number of AUs to be added
-
removeAU
Removes the specified number ofAUs from the student's registered AUs.- Parameters:
acadUnits- the number of AUs to be removed
-
planCourse
AddsCourses to the Student's plan.- Parameters:
course- The course to be added.courseIndex- The index to be added.- Returns:
CourseStatus.NOT_REGISTERED
-
addCourse
public CourseStatus addCourse(java.lang.String courseCode, java.lang.String courseIndex) throws java.lang.ExceptionAdds a course to theStudent's timetable. If there is no timetable clash, will try to register the course. If the course has no vacancies, the student will be put on the waitlist.- Parameters:
courseCode- theCoursecode of the desired course to be added, the student cannot be registered in the course nor on its waitlist.courseIndex- the couse index of the desired course to be added.- Returns:
- the course status that the course has been successfully added as.
- Throws:
java.lang.Exception- if the courseCode does not exist or there is a timetable clash.
-
dropCourse
public void dropCourse(java.lang.String courseCode) throws java.lang.ExceptionDrops a course from the student's timetable.- Parameters:
courseCode- the course code of the desired course to be dropped- Throws:
java.lang.Exception- if the courseCode does not exist has not been added by the student
-
changeIndex
public void changeIndex(java.lang.String code, java.lang.String currentInd, java.lang.String newInd) throws java.lang.ExceptionPuts the student in a different index of a registered course.- Parameters:
code- the course code of the registered course whose index we want to changecurrentInd- the current registered index of the registered coursenewInd- the new index of the registered course that the student is to be switched into- Throws:
java.lang.Exception- if the courseCode does not exist or has not been registered by the studentjava.lang.Exception- if the indices are not part of the course or the student is not registered in currentIndjava.lang.Exception- if the new index clashes with the student's timetable or the new index has no vancancies
-
clashes
public boolean clashes(java.lang.String courseCode, java.lang.String index)Checks if a course index of a course clashes with the student's timetable. Only checks with registered courses that are different from the course to be checked.- Parameters:
courseCode- the course code of the course to be checkedindex- the couse index to be checked- Returns:
- true if a clash is found, false if there are no clashes
-
addCourseFromWaitlist
Registers the student from waitlist.- Parameters:
courseIndex- the course index to be registered- Returns:
- true if registered successfully, false otherwise
- Throws:
java.lang.Exception- from thedropCourse(String)andaddCourse(String, String)methods
-
setIndex
Directly Adds aCourseIndexto aCoursein the courses Hashmap.- Parameters:
courseCode- The String value of the course code.courseIndex- the Index to be added.
-
removeIndex
Directly removes aCourseIndexfrom aCoursein the courses Hashmap.- Parameters:
courseCode- the String value of the course to be removed from.courseIndex- the String value of the index to be removed.- Returns:
- the Courseindex that was removed
-
simpleCopy
Creates a copy of this student object with minimal information. Used in CourseIndex objects to store tjust the necessary student information.- Returns:
- a stripped down copy of this student object
-
compareTo
Compares this student with the specified student for order. Returns a negative integer, zero, or a positive integer as this student is less than, equal to, or greater than the specified student. Order is based on first name, then last name, followed lastly by matriculation number.- Specified by:
compareToin interfacejava.lang.Comparable<Student>- Parameters:
o- the student to be compared- Returns:
- a negative integer, zero, or a positive integer as this student is less than, equal to, or greater than the specified student
-