Wrapper Classes FRQ Practice

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

Question 1 of 5

An ice rink stores a judge score in a wrapper.

(a) Write Double score = 9.0; then double copy = score; then score = 10.5; (b) State the values of copy and score after those statements. (c) Identify the unboxing assignment and the later autoboxing assignment. (d) Explain why copy is unchanged when score is reassigned.

Question 2 of 5

A radio tower reads numbers stored as text.

(a) Write int watts = Integer.parseInt("40"); and double gain = Double.parseDouble("2.5"); (b) State watts / 4 and gain * 2. (c) Identify the primitive return types of parseInt and parseDouble. (d) Write one assignment that stores the parseInt result in an Integer variable and name the conversion.

Question 3 of 5

Complete the table for a lantern festival counter. Then name the autoboxing and unboxing steps.

Step Statement p q
1 Integer p = 3; 3 not created
2 int q = p;
3 p = p + q;
4 q = q + 1;

Question 4 of 5

A shed method prints a local wrapper update, then the caller prints the original.

public class Shed {
    public void paint(Integer coats) {
        coats = coats + 2;
        System.out.print(coats);
    }
}

Integer start = 1;
Shed s = new Shed();
s.paint(start);
System.out.print(start);

(a) State the displayed text. (b) Explain the unboxing and autoboxing inside paint. (c) Explain why start is still 1 after paint returns.

Question 5 of 5

A salvage pile stores Integer tags. Show autoboxing into the list without writing a traversal algorithm.

import java.util.ArrayList;
ArrayList<Integer> pile = new ArrayList<Integer>();
int extra = 9;
pile.add(2);
pile.add(extra);
int first = pile.get(0);

(a) State first, pile.get(1), and extra after these statements. (b) Explain the autoboxing in both add calls. (c) Explain the unboxing into first. (d) Note that Integer is in java.lang while ArrayList still needs java.util.