Answer the two questions given below.
1. Consider the class OrderedPair, as given in the lesson. Suppose that we did not use a generic type, but instead omitted < T > and declared the data types of the private fields, method parameters, and local variable to be Object instead of T. What would the effect of these changes be on the use of the class?
2. Can you use the class OrderedPair, as defined in the lesson, to pair two objects having different and unrelated data types? Why or why not?
OrderedPair.java
public class OrderedPair< T > implements Pairable< T >{
private T first, second;
public OrderedPair(T f, T s){
first=f;
second=s;
}
public void setFirst(T f){
first=f;
}
public void setSecond(T s){
second=s;
}
public T getFirst(){
return first;
}
public T getSecond(){
return second;
}
public void changeOrder(){
T temp=first;
first=second;
second=temp;
}
public String toString(){
return("First => "+ first + " Second=> "+ second);
}
}
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.
The standard deviation of a list of numbers is a measure of how much the numbers deviate from the average. If the standard deviation is small, the numbers are clus-tered close to the average. If the standard deviation is large, the numbers are scat-tered far from the average. The standard deviation of a list of numbers n1, n2, n3, and so forth is defined as the square root of the average of the following numbers: (n1 - a)2, (n2 - a)2, (n3 - a)2, and so forth. The number a is the average of the numbers n1, n2, n3, and so forth.
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)