Practice Questions: Arrays
Consider the Student and Roster classes below.
public class Student
{
public String getName() { ... }
public char getSection() { ... }
public int getGrade() { ... }
public void setGrade(int grade) { ... }
}
public class Roster
{
private Student[] studentArray; //stores Student objects in first numStudents positions
private int numStudents; //number of students in studentArray
public Roster() { ... }
private void resizeIfFull() { ... }
}
Implement some or all of the following methods in Roster:
public void addStudent(Student student)
public int getGradeForStudentWithName(String name) //assume no duplicate names. return -1 if no such student
public String nameOfStudentWithHighestGrade() //assume no duplicate names, and at least 1 student
public void increaseAllGradesBy(int bonus) //up to a max grade of 100
public boolean hasStudentWithGrade(int grade)
public int countStudentsWithNamesOfLength(int length)
public double averageGradeForSection(char section) //assume at least 1 student
public Roster makeRosterForStudentsInSection(char section)
public void moveLastStudentToFrontWithoutChangingOrder() //e.g. ABCDE -> EABCD
public void removeStudentWithoutChangingOrder(String name)
public void reverseOrderOfRoster()