Class Course

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private int id
      course id (unique)
      private int level
      course level
      private String name
      course name
      private String professor
      professor teaching the course, null if none
      private HashSet<String> students
      students enrolled in the course (unique), empty if none
    • Constructor Summary

      Constructors 
      Constructor Description
      Course​(int id, String name, int level)
      Create a course.
    • Field Detail

      • id

        private int id
        course id (unique)
      • name

        private String name
        course name
      • level

        private int level
        course level
      • professor

        private String professor
        professor teaching the course, null if none
      • students

        private HashSet<String> students
        students enrolled in the course (unique), empty if none
    • Constructor Detail

      • Course

        public Course​(int id,
                      String name,
                      int level)
        Create a course. Initially there is no professor or student for the course.
        Parameters:
        id - course id
        name - course name
        level - course level
    • Method Detail

      • getId

        public int getId()
        Get the course id.
        Returns:
        course id
      • getName

        public String getName()
        Get the course name.
        Returns:
        course name
      • getLevel

        public int getLevel()
        Get the course level.
        Returns:
        course level
      • getProfessor

        public String getProfessor()
        Get the professor teaching the course.
        Returns:
        the professor, if none, null
      • getStudents

        public Collection<String> getStudents()
        Get the students enrolled in the course.
        Returns:
        the students, organized by ascending hash codes. if there are no students enrolled the list should be empty.
      • addProfessor

        public void addProfessor​(String username)
        Make a professor the instructor of this course. If another professor was teaching it, that information is lost.
        Parameters:
        username - the username of the professor
      • addStudent

        public boolean addStudent​(String username)
        Add a student to the course, if they are not enrolled, in constant time.
        Parameters:
        username - the username of the student
        Returns:
        whether the student was added or not
      • removeStudent

        public boolean removeStudent​(String username)
        Remove a student from the course, if they are enrolled, in constant time.
        Parameters:
        username - the username of the student to remove
        Returns:
        true if the student was removed, false if the student was not in the course
      • compareTo

        public int compareTo​(Course other)
        Compare courses naturally by ascending course id.
        Specified by:
        compareTo in interface Comparable<Course>
        Parameters:
        other - the other course to compare to
        Returns:
        a value less than 0 if this course has an id less the other course, 0 if the two courses have the same id, or a value greater than 0 if this course has an id greater than the other course.
      • equals

        public boolean equals​(Object other)
        Two courses are equal if they have the same course id.
        Overrides:
        equals in class Object
        Parameters:
        other - the other course
        Returns:
        true if
      • hashCode

        public int hashCode()
        The hash code of a course is the course's id.
        Overrides:
        hashCode in class Object
        Returns:
        the hash code
      • toString

        public String toString()
        Return a string representation of the course in the format:

        Course{id=ID, name=NAME, level=LEVEL, professor=PROF_USERNAME, students=STUDENT_LIST}

        Here, STUDENT_LIST should be a list of students username, displayed in traditional bracketed list format, but organized by ascending hash code. Note, in IntelliJ you can have this automatically generated if you go to Code then Generate and select toString.
        Overrides:
        toString in class Object
        Returns:
        the formatted string
      • main

        public static void main​(String[] args)
        The main method for testing the Course class.
        Parameters:
        args - command line arguments (unused)