import java.util.Arrays;

public class Roster {

    // array of current students in the course
    private Student[] theRoster;

    /**
     * number of non-null students in array
     * the first `enrollment` elements will be non-null
     * if theRoster.length > enrollment, the remaining values
     * are null
     */
    private int enrollment;

    // name of the course
    private String courseName;

    public Roster(int courseCap, String name) {
        theRoster = new Student[courseCap];
        this.courseName = name;
    }

    /**
     * Attempts to enroll a student in the Roster. Should have no effect if the Student
     * is already enrolled or if the course is at maximum enrollment.
     *
     * @param s The student to be enrolled
     * @return true if the Student could be enrolled, false otherwise
     */
    public boolean enrollStudentInCourse(Student s) {
        if (enrollment == theRoster.length || hasStudentRegistered(s)) {
            return false;
        }

        theRoster[enrollment] = s;
        enrollment++;
        return true;
    }

    /**
     *
     * @param s the Student to check for enrollment
     * @return true if the Student has registered for this course; false otherwise.
     */
    private boolean hasStudentRegistered(Student s) {
        for (int i = 0; i < enrollment; i++) {
            if (s.equals(theRoster[i])) {
                return true;
            }
        }
        return false;
    }

    /**
     * Prints a SORTED list of students so that they can find their names
     * to sign in on an attendance sheet.
     */
    public void printAttendanceList() {
        // IMPORTANT: Do not print NULL students

        // TODO
    }

    public static void main(String[] args) {
        Student harry = new Student("Harry", "Smith", "BA in LGIC", 1.7);
        Student stoner = new Student("William", "Stoner", "BA in ENGL", 4.0);
        Student blum = new Student("Ruben", "Blum", "BA in HIST", 3.4);
        Student shevek = new Student("Shevek", "", "BA in PHYS", 2.0);

        Roster basketWeaving = new Roster(5, "Intro to Basket Weaving");
        basketWeaving.enrollStudentInCourse(harry);
        basketWeaving.enrollStudentInCourse(stoner);
        basketWeaving.enrollStudentInCourse(blum);
        basketWeaving.enrollStudentInCourse(shevek);

        basketWeaving.printAttendanceList();

        Student otherHarry = new Student("Harry", "Smith", "BA in CIS", 1.4);
        basketWeaving.enrollStudentInCourse(otherHarry);

        basketWeaving.printAttendanceList();


    }
}

