Casting and Range of Variables FRQ Practice

Responses receive AI feedback against a rubric after submission. Scores are practice estimates.

Question 1 of 5

A bakery scales a recipe with int cups = 13; and int batches = 4;. Evaluate both expressions and explain why the results differ.

Expression
(double) cups / batches
(int) ((double) cups / batches)

Question 2 of 5

A wind sensor reports double wind = -8.7;. Evaluate (int) wind and (int) (wind - 0.5). Explain what each form is doing and why the results differ.

Question 3 of 5

Trace this update. Give the mathematical result of adding 4, the Java int result, and explain why they differ.

int fuel = Integer.MAX_VALUE - 2;
fuel += 4;

Question 4 of 5

A seating chart computes a midpoint index. The intended midpoint is 1800000000, which fits in an int. Explain why mid is not that value, state the intended mathematical midpoint, and write a corrected expression that avoids the overflowing sum.

int left = 1800000000;
int right = 1800000000;
int mid = (left + right) / 2;

Question 5 of 5

A trail app adds 0.35 km as a double after each segment. Explain why the stored total can disagree slightly with 0.35 times the number of segments. Name this kind of error. Propose an int representation that stays exact when all values and intermediate totals fit in an int, and give the stored amount for one 0.35 km segment.