Consider the following declaration of the class NumSequence, which has a constructor that is intended to initialize the instance variable seq to an ArrayList of numberOfValues random floating-point values in the range [0.0, 1.0).
public class NumSequence
{
private ArrayList seq;
// precondition: numberOfValues > 0
// postcondition: seq has been initialized to an ArrayList of
// length numberOfValues; each element of seq
// contains a random Double in the range [0.0, 1.0)
public NumSequence(int numberOfValues)
{
/* missing code */
}
}
Which of the following code segments could be used to replace /* missing code */ so that the constructor will work as intended?
I)
ArrayList seq = new ArrayList();
for (int k = 0; k < numberOfValues; k++)
seq.add(new Double(Math.random()));
II)
seq = new ArrayList();
for (int k = 0; k < numberOfValues; k++)
seq.add(new Double(Math.random()));
III)
ArrayList temp = new ArrayList();
for (int k = 0; k < numberOfValues; k++)
temp.add(new Double(Math.random()));
seq = temp;
A) II only
B) III only
C) I and II
D) I and III
E) II and III