Skip to main content
๐Ÿ“œ WAYPOINT LESSON

Checkpoint: Statistics Bureau

โญ beginnerโณ 45 min read๐Ÿ“ Lesson 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):

  1. int average(int[] scores) โ€” the mean rounded down to a whole number ((int) truncation is acceptable and expected).
  2. int passRate(int[] scores) โ€” the percentage of scores โ‰ฅ 60, rounded down (an integer 0โ€“100, not a double).
  3. 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.