Examlex

Solved

Assertions
for the Following Method, Identify Each of the Three

question 8

Essay

Assertions
For the following method, identify each of the three assertions in the table below as being either ALWAYS true, NEVER true or SOMETIMES true / sometimes false at each labeled point in the code. (can abbreviate as A/N/S)
public static int threeHeads() { // Counts coin tosses till we get heads 3x in a row.
Random rand = new Random();
int flip = 1;
int heads = 0;
int count = 0;
// Point A
while (heads < 3) {
// Point B
flip = rand.nextInt(2); // flip coin
if (flip == 0) { // heads
heads++;
// Point C
} else { // tails
// Point D
heads = 0;
}
count++;
}
// Point E
return count;
}
flip==0 heads ==0 flip > heads  Point A  Point B  Point C  Point D  Point E \begin{array}{|l|l|l|l|}\hline & f l i p==0 & \text { heads }==0 & \text { flip }>\text { heads } \\\hline \text { Point A } & & & \\\hline \text { Point B } & & & \\\hline \text { Point C } & & & \\\hline \text { Point D } & & & \\\hline \text { Point E } & & & \\\hline\end{array}


Definitions:

Grocery Coupons

Vouchers or codes that provide discounts on grocery items, typically used to promote products or encourage consumer purchases.

Train

A series of connected vehicles traveling on railways.

Ghrelin

A hormone produced by the stomach that stimulates appetite and signals the brain to increase food intake.

Glucose

A fundamental sugar crucial for powering living organisms and a key ingredient in various carbohydrates.

Related Questions