Post date: Dec 19, 2017 7:22:42 AM
Chapter 14: Generics and the ArrayList Class
14.2 Generics
Lab Ex 1 (InformIT.com):
Write a generic method to exchange the positions of two different elements in an array.
Lab Ex 2 (Programming Project 4 p. 831):
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 ArrayList of type T and returns as a double the standard deviation of the values in the ArrayList. Use the doubleValue() method in the Number class to retrieve the value of each number as a double. Refer to Programming Project 6.5 or this site for a definition of computing the standard deviation. 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 non-numeric elements (e.g., String)