Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Consider the incomplete method ChoiceOfThree. public int choiceOfThree() { // mi

ID: 3643418 • Letter: C

Question

Consider the incomplete method ChoiceOfThree.

public int choiceOfThree()
{
// missing code
}

Method choiceOfThree is intended to return one of the values 1, 2, 3, each with probability 1/3. Consider the following replacements for //missing code.

I. return (int)(Math.random() * 3);
II. return (int)(Math.random() * 3) + 1;
III. if(Math.random() < 1.0/3.0)
return 1;
else if (Math.random() < 2.0/3.0)
return 2;
else
return 3;

Which if these replacements for //missing code will make choiceOfThree work as intended?

A.) I only
B.) II only
C.) III only
D.) I and III only
E.) II and III only

Explanation / Answer

D is correct because these replacements for missing code will make choice of three work as intended