Anatomy of a Class FRQ Practice

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

Question 1 of 5

A studio keeps a count of live cables on a patch panel.

(a) Write a public class Patch with a private int cables, a public constructor Patch(int n) that stores n, a public plug(int extra) that adds extra to cables, and a public getCables that returns cables. (b) Explain why plug is public. (c) Explain why cables is private.

Question 2 of 5

Complete the table for two Patch objects. Then explain why plugging one panel does not change the other.

public class Patch {
    private int cables;
    public Patch(int n) {
        cables = n;
    }
    public void plug(int extra) {
        cables += extra;
    }
    public int getCables() {
        return cables;
    }
}
Step Statement desk cables stage cables
1 Patch desk = new Patch(2); 2
2 Patch stage = new Patch(2); 2
3 desk.plug(3);
4 stage.plug(1);

Question 3 of 5

A client has Reel tape = new Reel(40);

public class Reel {
    private int meters;
    public Reel(int n) {
        meters = n;
    }
    public int getMeters() {
        return meters;
    }
    private void rewind() {
        meters = 0;
    }
    public void clear() {
        rewind();
    }
}

(a) Classify each statement as compiles or does not compile: tape.meters = 0; int n = tape.getMeters(); tape.rewind(); tape.clear(); (b) Write one legal client statement that sets the stored meters to 0. (c) Explain the difference between calling rewind and calling clear.

Question 4 of 5

A student wants clients to raise a fader without calling the helper bump themselves.

public class Fader {
    private int level;
    public Fader() {
        level = 0;
    }
    private void bump() {
        level++;
    }
    public void fadeUp() {
        bump();
        bump();
    }
    public int getLevel() {
        return level;
    }
}

(a) State the value of getLevel after Fader f = new Fader(); f.fadeUp(); f.fadeUp(); (b) List the methods a client may call and the method a client may not call. (c) Explain how public methods are the class's client-facing API while private methods stay internal helpers.

Question 5 of 5

A draft OnAirLight leaks its state and hides the class.

private class OnAirLight {
    public boolean live;
    public OnAirLight() {
        live = false;
    }
}

(a) Rewrite the class header and the live attribute to match AP CSA anatomy, assuming the specification does not make live public. Add a public getter and a public method goLive that sets live to true. (b) Explain one problem with the original public field. (c) Explain one problem with the original private class header.