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> courses
    A list of courses the student is registered under or on waitlist for.
    private java.lang.String firstName
    The student's first name.
    private Gender gender
    The student's Gender.
    private java.lang.String lastName
    The student's last name.
    private java.lang.String matricNumber
    The student's unique, 9-character matriculation number.
    static int maxAUs
    The maximum number of AUs that a Student can take.
    private java.lang.String nationality
    The student's nationality.
    private int registeredAUs
    The student's number of registered Academic Units.
    private static long serialVersionUID
    The 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 void addAU​(AU acadUnits)
    Adds the specified number of AUs to the student's registered AUs.
    CourseStatus addCourse​(java.lang.String courseCode, java.lang.String courseIndex)
    Adds a course to the Student's timetable.
    boolean addCourseFromWaitlist​(CourseIndex courseIndex)
    Registers the student from waitlist.
    void changeIndex​(java.lang.String code, java.lang.String currentInd, java.lang.String newInd)
    Puts the student in a different index of a registered course.
    boolean clashes​(java.lang.String courseCode, java.lang.String index)
    Checks if a course index of a course clashes with the student's timetable.
    int compareTo​(Student o)
    Compares this student with the specified student for order.
    void dropCourse​(java.lang.String courseCode)
    Drops a course from the student's timetable.
    int getAU()
    Returns the student's current number of registered Academic Units (AUs).
    Course getCourse​(java.lang.String courseCode)
    Returns a Course object 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.String getFirstName()
    Returns the student's first name.
    Gender getGender()
    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.String getLastName()
    Returns the student's last name.
    java.lang.String getMatricNumber()
    Returns the student's matriculation number.
    java.lang.String getNationality()
    Returns the student's nationality.
    static boolean isValidMatricNo​(java.lang.String matricNo)
    Checks if a String can be used as a matriculation number.
    static boolean isValidNewMatricNo​(java.lang.String matricNo)
    Checks if a String can be used as a new matriculation number.
    CourseStatus planCourse​(Course course, CourseIndex courseIndex)
    Adds Courses to the Student's plan.
    private void removeAU​(AU acadUnits)
    Removes the specified number of AUs from the student's registered AUs.
    protected Course removeCourse​(java.lang.String courseCode)
    Directly removes a Course from the courses Hashmap.
    CourseIndex removeIndex​(java.lang.String courseCode, java.lang.String courseIndex)
    Directly removes a CourseIndex from a Course in the courses Hashmap.
    protected void setCourse​(Course course)
    Directly adds a Course to the Hashmap.
    void setIndex​(java.lang.String courseCode, CourseIndex courseIndex)
    Directly Adds a CourseIndex to a Course in the courses Hashmap.
    Student simpleCopy()
    Creates a copy of this student object with minimal information.

    Methods inherited from class java.lang.Object

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

    • serialVersionUID

      private static final long serialVersionUID
      The unique ID of the class for Serialisation.
      See Also:
      Constant Field Values
    • matricNumber

      private java.lang.String matricNumber
      The student's unique, 9-character matriculation number.
    • firstName

      private java.lang.String firstName
      The student's first name.
    • lastName

      private java.lang.String lastName
      The student's last name.
    • courses

      private java.util.HashMap<java.lang.String,​Course> courses
      A list of courses the student is registered under or on waitlist for.
    • gender

      private Gender gender
      The student's Gender.
    • nationality

      private java.lang.String nationality
      The student's nationality.
    • registeredAUs

      private int registeredAUs
      The student's number of registered Academic Units.
    • maxAUs

      public static final int maxAUs
      The 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 number
      firstName - the student's first name
      lastName - the student's last name
      gender - the student's gender
      nationality - 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 number
      firstName - the student's first name
      lastName - the student's last name
      password - the student's password for accessing the STARS system
      gender - the student's gender
      nationality - 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

      public Gender 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

      public Course getCourse​(java.lang.String courseCode)
      Returns a Course object that the Student has registered for.
      Parameters:
      courseCode - The String value of the course.
      Returns:
      A Course Object.
    • getCourses

      public Course[] getCourses​(CourseStatus courseStatus)
      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

      protected Course removeCourse​(java.lang.String courseCode)
      Directly removes a Course from the courses Hashmap.
      Parameters:
      courseCode - The code of the course to be removed
      Returns:
      a Course object that is removed from the Hashmap.
    • setCourse

      protected void setCourse​(Course course)
      Directly adds a Course to the Hashmap.
      Parameters:
      course - The course to be added.
    • getIndices

      public CourseIndex[] getIndices​(CourseStatus courseStatus)
      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

      private void addAU​(AU acadUnits)
      Adds the specified number of AUs to the student's registered AUs.
      Parameters:
      acadUnits - the number of AUs to be added
    • removeAU

      private void removeAU​(AU acadUnits)
      Removes the specified number of AUs from the student's registered AUs.
      Parameters:
      acadUnits - the number of AUs to be removed
    • planCourse

      public CourseStatus planCourse​(Course course, CourseIndex courseIndex)
      Adds Courses 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.Exception
      Adds a course to the Student'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 - the Course code 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.Exception
      Drops 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.Exception
      Puts the student in a different index of a registered course.
      Parameters:
      code - the course code of the registered course whose index we want to change
      currentInd - the current registered index of the registered course
      newInd - 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 student
      java.lang.Exception - if the indices are not part of the course or the student is not registered in currentInd
      java.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 checked
      index - the couse index to be checked
      Returns:
      true if a clash is found, false if there are no clashes
    • addCourseFromWaitlist

      public boolean addCourseFromWaitlist​(CourseIndex courseIndex) throws java.lang.Exception
      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 the dropCourse(String) and addCourse(String, String) methods
    • setIndex

      public void setIndex​(java.lang.String courseCode, CourseIndex courseIndex)
      Directly Adds a CourseIndex to a Course in the courses Hashmap.
      Parameters:
      courseCode - The String value of the course code.
      courseIndex - the Index to be added.
    • removeIndex

      public CourseIndex removeIndex​(java.lang.String courseCode, java.lang.String courseIndex)
      Directly removes a CourseIndex from a Course in 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

      public Student 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

      public int compareTo​(Student o)
      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:
      compareTo in interface java.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