Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Consider a class, HighSchoolClass, which represents a class of high school st

ID: 3623482 • Letter: 1

Question

1. Consider a class, HighSchoolClass, which represents a class of high school students, i.e., all the students in a particular grade level. The students are stored as Student objects in an array that is kept in sorted order by the students’ names.

public class HighSchoolClass
{
private Student[] students;
// constructors and other data fields not shown

// returns the valedictorian of the class
public Student getValedictorian()
{
// to be implemented
}

//returns the percentage of students in the honors program
public double getHonorsPercent()
{
// to be implemented
}
}

The following are some of the public methods of the Student class:

// returns the student’s grade point average
public double getGPA()

// returns true if the student is in the honors program
public boolean isHonors()


a. The getValedictorian method returns the valedictorian of the class, that is, the student with the highest grade point average. (You may assume that the lowest possible GPA is 0.) Implement getValedictorian.

b. The getHonorsPercent method returns the percentage of students in teh class who are in the honors program. Implement getHonorsPercent.

c. An alternate implementation for HighSchoolClass is being considered, in which the students are stored in an ArrayList instead of an array. Show how the declaration of the datafield students would look in this alternate design.

Explanation / Answer

a. public Student getValedictorian() { Student val; val = students[0]; for (int i = 0; i val.getGPA()) val = students[i]; } return val; } b. public double getHonorsPercent() { int num = 0; double per = 0.0; for (int i = 0; i