This is what I have so far. Am I on the right track because I am kind of confused? I understand what it is asking for, but I do not really know how to put that in code. I received the error: type ArrayList does not take parameters at line 9 and 11. Can someone help?
Write a method called removeLowerThan that takes a double, number,and an integer, length, as parameters. The method should create an ArrayList and fill it with length number of Doubles. The Doubles should be Random! You must use the Random class. The method should then remove all values that are less than number and return the revised ArrayList.
Write a method called removeLowerThan that takes a double, number,and an integer, length, as parameters. The method should create an ArrayList and fill it with length number of Doubles. The Doubles should be Random! You must use the Random class. The method should then remove all values that are less than number and return the revised ArrayList.
Code:
import java.util.*;
public class ArrayList
{
public ArrayList()
{
}
public ArrayList<Double> removeLowerThan(double number, int length)
{
ArrayList<Double> list = new ArrayList<Double>();
Random Random = new Random();
for (int i = 0; i <length; i++)
{
double r = (double)Random.nextInt(length);
list.add(r);
}
System.out.print(list);
int j = 0;
while (j < length)
{
if (list.get(j) < number)
{
list.remove(j);
}
j++;
}
for (Double d : list)
System.out.print(d);
return list;
}
}
Comment