Question: Write a generic class, MyMathClass, with a type parameter T where T is a numeric object type (e.g., Integer, Double, or any class that extends

 Write a generic class, MyMathClass, with a type parameter T whereT is a numeric object type (e.g., Integer, Double, or any class

Write a generic class, MyMathClass, with a type parameter T where T is a numeric object type (e.g., Integer, Double, or any class that extends java.lang. Number). Add a method named standardDeviation that takes an ArrayListof type T and returns as a double the average of the values in the ArrayList. Use the doubleValue0 method in the Number class to retrieve the value of each number as a double. Test your method with suitable data. Your program should generate a compile-time error if your standard deviation method is invoked on an ArrayList that is defined for nonnumeric elements (e.g., Strings) You can use the following sample code to start. Notice how the average method is working and try to implement a generic standard deviation method. The rule for standard deviation is: class MyMathClass public MyMathClass () *To compute the standard deviation, we must compute the average. *This takes an arraylist of numeric types and returns the average, * as a double. * @param arr ArrayList of a numeric type *Creturn double Average of the elements in arr public double average (ArrayList arr) double total = 0; for (T val : arr) // Calculate each numeric type as a double total += val . doubleValue ( ) ; return total / arr.size); * Computes the standard deviation of the values in arr. * Standard Deviation Sqrt( (Sumi-1_to_N (element i - ave)2) / N) *where N is the number of elements in the array * @param arr ArrayList of a numeric type * @return double Standard deviation of the elements in arr

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!