Skip to main content

Pilot · Lab P02 · 45 minutes

Repair the eligibility checker

A club sign-up checker has two separate bugs: a condition that lets the wrong students in, and a counter that never gets past 1. Find each bug with a failing input, record expected and observed results, then repair both.

Predict first

Write your predictions before you use the tool.

  1. The rule is: a student may join if they are at least 14 AND the club has at least one place. Predict the result for (13, 2), (14, 0) and (14, 1).
  2. The counter fragment should end at 3 after three sign-ups. Read it and predict what it actually ends at.

Practice tool

The comparison tool evaluates the two fixed fragments below for the values you choose and shows each part of the condition. It does not run your code. Observed results here come from the fixed faulty fragments, so you can see a bug happen before you fix it.

Condition and counter comparison · fixed fragments

Fragment 1: (age ≥ 14) OR (places > 0)

Whole number 0–999.

Whole number 0–999.

age ≥ 14 is false; places > 0 is true; false OR true → true

Fragment 2: three sign-ups

signups after each pass: 1, 1, 1

DISPLAY shows 1

Starter

Fragment 1 (faulty): eligibility · AP CSP pseudocode
PROCEDURE canJoin(age, places){  RETURN((age ≥ 14) OR (places > 0))}
Fragment 2 (faulty): counting sign-ups · AP CSP pseudocode
REPEAT 3 TIMES{  signups ← 0  signups ← signups + 1}DISPLAY(signups)

Worked case

A failing input is one where the expected result (from the rule) differs from the observed result (from the code). Record both, then explain which part of the code caused the difference.

Worked bug record for fragment 1
Input (age, places)ExpectedObservedWhy
(13, 2)falsetrueOR is true when places > 0 alone is true, so age is ignored.

Build

  1. Use the comparison tool to find a failing input for fragment 1. Record input, expected, observed.
  2. Repair fragment 1 so all three stated cases give the expected result.
  3. Use the trace to see what signups holds after each pass of fragment 2. Record the failing observation.
  4. Repair fragment 2 by moving the reset so the total reaches 3. Re-trace to confirm.

Tests

Tests for this lab
InputExpectedWhy this test
(13, 2)falseToo young, even though places remain.
(14, 0)falseOld enough, but the club is full.
(14, 1)trueBoth parts true. Note 14 is included by ≥.
three sign-ups from 03The reset must happen once, before the loop.

Explain and reflect

Explain

  1. Explain, using one failing input, why OR is wrong for this rule.
  2. Explain why the counter ended at 1 and why moving one line fixes it.

Reflect

  1. Which bug would a user notice first, and how?
  2. Write one more input that would have caught the OR bug.

What this lab does not do

  • The tool evaluates only the two fixed fragments; it does not run your repaired code.
  • Your repairs are checked by your teacher.
  • Nothing you choose in the tool is saved.