tally
Value
| 0
| 1
| 2
| 3
| 4
| 5
| 6
| 7
| 8
| 9
| 10
| 11
| 12
| 13
| 14
| 15
| Frequency
| 0
| 0
| 10
| 5
| 10
| 0
| 7
| 1
| 0
| 6
| 0
| 10
| 3
| 0
| 0
| 1
| |
In writing calculateModes you may call the Stats method findMax specified below which returns the maximum value in array. Using the example array, findMax(tally) returns 10. Do NOT write findMax.
/**
* precondition: nums.length > 0
* postcondition: returns the maximal value in nums
*/
private static int findMax(int[] nums)
Do NOT write the body of findMax
In writing calculateModes, you may call method findMax
specified above.
Complete method calculateModes below.
/** * precondition: tally.length > 0 * postcondition: returns an int array that contains the modes(s); * the array's length equals the number of modes. */ public static int[] calculateModes(int[] tally)
In the example reprinted below, the first ten data values are 2, the next five data values are 3, and the next ten data values are 4. For this example, kthDataValue(tally, 1) returns 2, kthDataValue(tally, 14) returns 3, kthDataValue(tally, 15) returns 3, and kthDataValue(tally, 16) returns 4.
Value
| 0
| 1
| 2
| 3
| 4
| 5
| 6
| 7
| 8
| 9
| 10
| 11
| 12
| 13
| 14
| 15
| Frequency
| 0
| 0
| 10
| 5
| 10
| 0
| 7
| 1
| 0
| 6
| 0
| 10
| 3
| 0
| 0
| 1
| |
Complete method kthDataValue below.
/** * precondition: tally.length > 0; * 0 < k <= total number of values in data collection * postcondition: returns the kth value in the data collection * represented by tally */ public static int kthDataValue(int[] tally, int k)