Question: JAVA:::: binarySearch method in the Arrays class. Modify the getStudentId method in the GradeBook class so that it uses the binarySearch method instead. Take note

JAVA:::: binarySearch method in the Arrays class. Modify the getStudentId method in the GradeBook class so that it uses the binarySearch method instead.

Take note that there are many overloads of the binarySearch method. We are only interested in the method that takes an Object[] as its parameter. For now, consider that String[] can take the place of Object[]. We will discuss how and why this works when we talk about inheritance and polymorphism in class.

public class GradeBook{ private enum EnrollmentStatus {OPEN, FULL}; private EnrollmentStatus enrollment; private int occupiedSlots; private int maxSlots; private String[] names; private int[][] grades; public GradeBook(int maxSlots){ this.occupiedSlots = 0; this.maxSlots = maxSlots; enrollment = EnrollmentStatus.OPEN; names = new String [maxSlots]; grades = new int[maxSlots][5]; } public int getMaxSlots(){ return maxSlots; } public int getAvailbleSlots(){ return maxSlots - occupiedSlots; } public boolean enroll(String name){ if(enrollment == EnrollmentStatus.FULL) return false; else { names[occupiedSlots++] = name; if(occupiedSlots>=maxSlots) enrollment = EnrollmentStatus.FULL; } return true; } public int getStudentId(String name){ int index = -1; for(int i=0; i 
import java.util.Random; public class Driver{ public static void main(String[] args){ Random gRandom = new Random(); GradeBook gb = new GradeBook(20); gb.enroll("Anh Mai"); gb.enroll("Jose Garcia"); gb.enroll("Pei Lin"); for(int i=0; i<3; i++) for(int j=0; j<5; j++) gb.assignGrade(i, j+1, gRandom.nextInt(11)); System.out.println(gb.getStudentAverage(0)); } } 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!