Write a Statistics
class that has the following static methods:
sampleSize(double[] arr)
- returns the number of values in the arraymaximum(double[] arr)
- identifies and returns the largest value in the arrayminimum(double[] arr)
- identifies and returns the smallest value in the arraymean(double[] arr)
- calculates and returns the mean (average) of the values in the arraymedian(double[] arr)
- calculates and returns the middle value in the array after it has been sorted.
Arrays.sort(arr)
method to sort your array for this method. You'll need to import java.util.Arrays
to use that static method.mode(double[] arr)
- returns the value that occurs most frequently in the array of values.
null
. Because we want to return a null
value, and this can only correspond with objects, the return type of this method should be a Double
, the wrapper class for double objects.The following Arrays can be used to test your class:
arr = {1, 0, 3, 8, 4, 2, 1, 9, 20, 100}
sampleSize(arr) --> 10
maximum(arr) --> 100
minimum(arr) --> 0
mean(arr) --> 14.8
median(arr) --> 3.5
mode(arr) --> 1
arr = {2, 3, 2, 3, 2, 17, -5}
sampleSize --> 7
maximum --> 17
minimum --> -5
mean --> 3.4285714285714284
median --> 2.0
mode --> 2.0
arr = {1, 2, 3, 4, 5}
mode --> null