Checkpoint: Statistics Bureau
beginner45 min readLesson 20 of 180
Average, pass rate, and second-largest in single passes — accumulators, counters, and extremum tracking under one roof.
The Statistics Bureau processes test scores in one pass each.
Implement three methods over an int[] scores (each 0–100; the array is
never empty):
int average(int[] scores)— the mean rounded down to a whole number ((int)truncation is acceptable and expected).int passRate(int[] scores)— the percentage of scores ≥ 60, rounded down (an integer 0–100, not a double).int secondLargest(int[] scores)— the second-largest DISTINCT value; every score is guaranteed to appear at least twice or the array is guaranteed to hold at least two distinct values — when all values are identical, return that value itself.
One loop per method (no Arrays.sort — this is a loops exercise), each
carrying only the state it needs. average({70, 80, 91}) is 80;
passRate({70, 80, 91}) is 100; secondLargest({90, 90, 85}) is 85.