Checkpoint: the two-branch machine
Challenge on lesson: Checkpoint: full trace under misdirection
CHALLENGE
Difficulty: advanced+25 XP
Trace this class and sequence, then return the **final** value of probe():
``java
public class Gate {
private static int visits = 0;
private int passes;
private int blocked;
public Gate() { passes = 0; blocked = 0; }
public void enter(boolean ok) {
visits++;
if (ok) { passes++; }
else {
blocked++;
if (blocked > 2) { passes = 0; }
}
}
public int probe() { return passes * 10 + blocked; }
}
`
Calls: new Gate(), then enter(true); enter(false); enter(false); enter(false); enter(true);`.
Press Submit to check your solution.
Back to lesson: Checkpoint: full trace under misdirection