A program is to simulate plant life under harsh conditions. In the program, plants die randomly according to some probability. Here is part of a Plant class defined in the program.
public class Plant
{
/** probability that plant dies, a real number between 0 and 1 */
private double probDeath;
public Plant(double plantProbDeath, < other parameters >)
{
probDeath = plantProbDeath;
< initialization of other instance variables >
}
/** Plant lives or dies. */
public void liveOrDie()
{
/* statement to generate random number */
if (/* test to determine if plant dies */)
< code to implement plant’s death >
else
< code to make plant continue living >
}
//Other variables and methods are not shown.
}
Which of the following are correct replacements for
(1) /* statement to generate random number */ and
(2) /* test to determine if plant dies */?
(A) (1) double x = Math.random();
(2) x == probDeath
(B) (1) double x = (int) (Math.random());
(2) x > probDeath
(C) (1) double x = Math.random();
(2) x < probDeath
(D) (1) int x = (int) (Math.random() * 100);
(2) x < (int) probDeath
(E) (1) int x = (int) (Math.random() * 100) + 1;
(2) x == (int) probDeath