Loading...
Loading...
A college collects feedback on a workshop. Declare enum Rating with POOR(1), AVERAGE(2), GOOD(3) and EXCELLENT(4), where the number is a private final points field.
Count each rating, print the counts in the enum's order, then the most common rating (on a tie, the one declared first) and the average points with two decimals.
RATING: count, then Most common: RATING, then Average: x.xx.Example
Input
7 GOOD EXCELLENT GOOD POOR GOOD AVERAGE EXCELLENT
Output
POOR: 1 AVERAGE: 1 GOOD: 3 EXCELLENT: 2 Most common: GOOD Average: 2.86
GOOD appears 3 times; the points add up to 20, and 20 / 7 = 2.86.
Try the problem first. Open one hint at a time.
One int[] slot per constant, indexed by ordinal().
Replace the best rating only when a count is strictly greater; that keeps the earlier one on a tie.
String.format("%.2f", sum / (double) n) gives two decimals.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor