public void addStudent(Student student) { resizeIfFull(); studentArray[numStudents] = student; numStudents++; } public int getGradeForStudentWithName(String name) //assume no duplicate names. return -1 if no such student { for(int i = 0; i < numStudents; i++) { String n = studentArray[i].getName(); if(n.equals(name)) return studentArray[i].getGrade(); } return -1; } public String nameOfStudentWithHighestGrade() //assume no duplicate names, and at least 1 student { int max = studentArray[0].getGrade(); int indexOfMax = 0; for(int i = 1; i < numStudents; i++) { if (studentArray[i].getGrade() > max) { max = studentArray[i].getGrade(); indexOfMax = i; } } return studentArray[indexOfMax].getName(); } public void increaseAllGradesBy(int bonus) //up to a max grade of 100 { for(int i = 0; i < numStudents; i++) { int grade = studentArray[i].getGrade() + bonus; if (grade > 100) grade = 100; studentArray[i].setGrade(grade); } } public boolean hasStudentWithGrade(int grade) { for(int i = 0; i < numStudents; i++) { if (grade == studentArray[i].getGrade()) return true; } return false; } public int countStudentsWithNamesOfLength(int length) { int count = 0; for(int i = 0; i < numStudents; i++) { int x = studentArray[i].getName().length(); if (x == length) count++; } return count; } public double averageGradeForSection(char section) //assume at least 1 student { int numInSection = 0; //keeps track of total number of students in the section int runningTotal = 0; //keeps track of the grade total in the section for(int i = 0; i < numStudents; i++) { if(studentArray[i].getSection() == section) { runningTotal += studentArray[i].getGrade(); numInSection++; } } double ave = (double)(runningTotal) / (double)(numInSection); return ave; } public Roster makeRosterForStudentsInSection(char section) { Roster r = new Roster(); for(int i = 0; i < numStudents; i++) { if(studentArray[i].getSection() == section) { r.addStudent(studentArray[i]); } } return r; } public void moveLastStudentToFrontWithoutChangingOrder() //e.g. ABCDE -> EABCD. assume numStudents > 0 { Student last = studentArray[numStudents - 1]; for (int i = numStudents - 1; i > 0; i--) { studentArray[i] = studentArray[i-1]; } studentArray[0] = last; } public void removeStudentWithoutChangingOrder(String name) //assume no more than one student with this name { for(int i = 0; i < numStudents; i++) { if (studentArray[i].getName().equals(name)) { for (int to = i; to < numStudents - 1; to++) { studentArray[to] = studentArray[to + 1]; } studentArray[numStudents-1] = null; numStudents--; return; } } } public void reverseOrderOfRoster() { Student[] tmp = new Student[studentArray.length]; for(int i = 0; i < numStudents; i++) { tmp[i] = studentArray[numStudents - i - 1]; } studentArray = tmp; }