FRQ: Student Record
Consider a grade-averaging scheme in which the final average of a student’s scores is computed differently from the traditional average if the scores have “improved.” Scores have improved if each score is greater than or equal to the previous score. The final average of the scores is computed as follows.
A student has n scores indexed from 0 to n-1. If the scores have improved, only those scores with indexes greater than or equal to n/2 are averaged. If the scores have not improved, all the scores are averaged.
The following table shows several lists of scores and how they would be averaged using the scheme described above.
50,50,20,80,53
No
(50+50+20+83+53)/5.0=50.6
20,50,50,53,80
Yes
(50+53+80)/3.0=61.0
20,50,50,80
Yes
(50+80)/2.0=65.0
Consider the following incomplete StudentRecord class declaration. Each StudentRecord object stores a list of that student’s scores and contains methods to compute that student’s final average.
The StudentRecord class is as follows, you need to implement all the methods, including its constructor:
IMPORTANT: To implement finalAverage(), you have to correctly call average() and hasImproved() to receive full credit.
int[] arr1 = {50,50,20,80,53};
Create an array arr1.
int[] arr2 = {20,50,50,53,80};
Create an array arr2.
int[] arr3 = {20,50,50,80};
Create an array arr3
StudentRecord s1 = new StudentRecord(arr1);
Create a new student record s1
StudentRecord s2 = new StudentRecord(arr2);
Create a new student record s2
StudentRecord s3 = new StudentRecord(arr3);
Create a new student record s3
s1.average(2,4);
51.0
Return the average between index 2 and 4 of arr1.
s3.average(1,2);
50.0
Return the average between index 1 and 2 of arr3.
s1.hasImproved();
false
The scores of s1 doesn't improve.
s2.hasImproved();
true
The scores of s2 does improve.
s3.hasImproved();
true
The scores of s3 does improve.
s1.finalAverage();
50.6
(50+50+20+83+53)/5.0=50.6
s2.finalAverage();
61.0
(50+53+80)/3.0=61.0
s3.finalAverage();
65.0
(50+80)/2.0=65.0
Last updated