Class SIS


  • public class SIS
    extends Object
    The main program and "front end" for the Student Information System. It is run on the command line in two ways:

    $ java SIS course-file professor-file student-file
    $ java SIS course-file professor-file student-file input-file

    Its job is to create the backend by passing it the course, professor and student input files (see Backend class documentation), and then run an loop reading input (either from standard input (first way of running), or from a file of input commands (second way of running)).

    The commands the system accepts can be found by running the 'help' command:

    course {id}: list a course
    courses: list all courses (by course id)
    enroll {username} {id}: enroll a student in a course
    help: this message
    professor {username}: list courses taught by professor (by course level then by course name)
    student {username}: list courses taken by student (by course name)
    unenroll {username} {id}: unenroll a student from a course
    users: list all users (alphabetically by username)
    quit: quit SIS

    • Constructor Detail

      • SIS

        public SIS​(String courseFile,
                   String professorFile,
                   String studentFile)
            throws FileNotFoundException
        Create the backend.
        Parameters:
        courseFile - the course file
        professorFile - the professor file
        studentFile - the student file
        Throws:
        FileNotFoundException - if any of the files cannot be found
    • Method Detail

      • helpMessage

        private void helpMessage()
        A helper method for displaying the help message.
      • enrollStudent

        private void enrollStudent​(String username,
                                   int courseId)
        A helper method for the enroll command. It calls verifyStudentCourse to verify the users exists, is a student, and the course exists. If the student is found to already be enrolled in the course when enrolling with Backend::enrollStudent, the following message should be displayed:

        student {username} already enrolled in course

        Parameters:
        username - name of the user
        courseId - the course id
      • listAllCourses

        private void listAllCourses​(Collection<Course> courses)
        A helper method that list all courses. This is called when the courses command is entered in mainLoop() and Backend::getAllCourses() is passed in. It is also called when listUser() is invoked to display the courses for a specific user, e.g.:

        > courses
        Course{id=1, name='Computer_Science_1', level=100, professor=mjk, students=[aa0, bb3, cc2]}
        ...

        Parameters:
        courses - the courses to list
      • listAllUsers

        private void listAllUsers()
        A helper method for the users command. This lists all users from Backend::getAllUsers(), e.g.

        > users
        User{username='bb1', type=STUDENT, courses=[Principles_of_Data_Management]}
        ...
      • listCourse

        private void listCourse​(int courseId)
        A helper method for the course command. It lists the details for a specific course, using Backend::getCourse(), e.g.

        > course 4
        Course{id=4, name='Principles_of_Data_Management', level=300, professor=mjk, students=[bb1]}
        ...

        If a course does not exist it displays the message:

        course {courseId} does not exist!

        Parameters:
        courseId - the course id
      • listUser

        private void listUser​(String username)
        A helper method for the professor and student commands. It lists the details for a specific user. It calls listAllCourses with the results of Backend::getCourseUser(). If a user does not exist it displays the message:

        {username} does not exist!

        Parameters:
        username - the username
      • unenrollStudent

        private void unenrollStudent​(String username,
                                     int courseId)
        A helper method for the unenroll command. It calls verifyStudentCourse() first to verify the user and course. It then calls Backend::unenrollStudent to attempt to unenroll the student from the course. If the student was not enrolled in the course it displays the message:

        student {username} was not enrolled in course {courseId}!

        Parameters:
        username - the students username
        courseId - the course id
      • verifyStudentCourse

        private boolean verifyStudentCourse​(String username,
                                            int courseId)
        A helper method used by enrollStudent() and unenrollStudent(). It verifies in the following order:

        1. Does the username exist? Uses Backend::userExists. If the user doesn't exist display the following message (and return false):

        user {username} does not exist!

        2. Is the user a student? Uses Backend::isStudent. If the user is not a student display the following message (and return false):

        user {username} is not a student!

        3. Does the course exist? Uses Backend::courseExists. If the course does not exist display the following message (and return false):

        course {courseId} does not exist!

        If all checks return true, it returns true.
        Parameters:
        username - the username
        courseId - the course id
        Returns:
        true if the student and course are verified, false otherwise
      • mainLoop

        public void mainLoop​(Scanner in,
                             boolean stdin)
        The main loop runs through the input commands that 'in' is attached to via the Scanner. It prompts with '>'. If the command is valid it calls the appropriate private helper method. Otherwise it should display the message:

        Unrecognized command {command}

        And reprompts the user.
        Parameters:
        in - a Scanner attached to the input (either stdin or the input file)
        stdin - tells whether the scanner is attached to stdin or not. If not, the input command should be displayed to standard output so it is easier to follow the output.