I am working on an assignment to write a generic class called MyStatisticsCla ss with type parameter T where T is a numeric object. with a method called standardDeviati on that takes a ArrayList of type T and returns a double. I am getting the following error when I try to compile:
[code=java]MyStatisticsCla ss.java:27: standardDeviati on(java.util.Ar rayList<T>) in MyStatisticsCla ss<T> cannot be applied to (java.util.Arra yList<java.lang .Double>)
Double result = standardDeviati on(numbers);[/code]
Here are some tid bits of the code I have:
[code=java] public static void main(String[] args)
{
ArrayList<Doubl e> numbers = new ArrayList<Doubl e>();
//some random numbers are assigned to numbers here
Double result = standardDeviati on(numbers);//this is causing the error
}
public double standardDeviati on(ArrayList<T> a)
{
double average = calcAverage(a);
double top = 0.0;
//calculate the standard deviation
for (int i = 0; i < a.size(); i++)
{
top = top + Math.pow(a.get( i).doubleValue( ) - average, 2);
}
return Math.sqrt(top / average);
}[/code]
Anyone know what I am doing wrong? I can't seem to figure it out! Thanks for any help.
[code=java]MyStatisticsCla ss.java:27: standardDeviati on(java.util.Ar rayList<T>) in MyStatisticsCla ss<T> cannot be applied to (java.util.Arra yList<java.lang .Double>)
Double result = standardDeviati on(numbers);[/code]
Here are some tid bits of the code I have:
[code=java] public static void main(String[] args)
{
ArrayList<Doubl e> numbers = new ArrayList<Doubl e>();
//some random numbers are assigned to numbers here
Double result = standardDeviati on(numbers);//this is causing the error
}
public double standardDeviati on(ArrayList<T> a)
{
double average = calcAverage(a);
double top = 0.0;
//calculate the standard deviation
for (int i = 0; i < a.size(); i++)
{
top = top + Math.pow(a.get( i).doubleValue( ) - average, 2);
}
return Math.sqrt(top / average);
}[/code]
Anyone know what I am doing wrong? I can't seem to figure it out! Thanks for any help.
Comment