◀ 11.1b11.1c11.1d ▶

11.1c — Create PT: Build Day 2

Day 1 built the list (11.1b); today builds the ALGORITHM — the procedure that earns its rubric row by doing all three at once: sequencing (statements in order), selection (if), iteration (loop). This is the piece the video will feature and WR2a will explain. Make it proud.

Build Day ~50 min

The algorithm contract — annotate yours to match:

// SEQUENCING: these lines run in THIS order, on purpose
public int ScoreHand(List<Card> cards, int bonus)   // ← parameters
{
    int total = 0;                                    // 1. start
    for (int i = 0; i < cards.Count; i++)            // 2. ITERATION
    {
        Card c = cards[i];
        if (c.cost <= 3)                             // 3. SELECTION
        {
            total += c.attack + bonus;
        }
        else
        {
            total += c.attack / 2;
        }
    }
    if (total > 20) { total = 20; }                   // 4. SELECTION, again
    return total;                                     // 5. output
}

Why the exam loves this shape: it is not hard; it is COMPLETE. Sequencing is the spine, selection makes decisions, iteration handles many items, and the procedure takes PARAMETERS so callers can reuse it. Your 10.2d AI score method IS this algorithm — you have been writing rubric answers all year without knowing the rubric's name.

Build order for the day:

  1. Write the procedure with parameters (two beats: what it processes, what it decides on). Name the parameters well — they appear in your screenshots and WR.
  2. Call it from three different places — a call per context proves reuse, and graders read calls as "this is real behavior, not a demo."
  3. Print before/after: Debug.Log(...) the input state and output state at each call site. Input → behavior → output, made visible.
  4. Break it on purpose (5 min): empty list, zero, one item, giant item. Fix what crashes. The PT video cannot crash — you have ONE take.
Close of Day ~5 min

Socratic: Sequencing, Selection, Iteration

  1. Your procedure does all three at once. Which line is the selection, and what would happen if it were deleted?
  2. A grader must be able to find the parameter and the call. Can you name both from memory without opening the file?
  3. You built this before the input and output the video will show. What is the risk in that order, and what did you do about it today?

Checkpoint — before moving on, you must be able to:

  • Label S/S/I in your algorithm line by line
  • Show three call sites with different arguments
  • Prove the algorithm survives edge inputs
  • Read your WR2a paragraph out loud in under 40 seconds

Reference Docs

Need a deeper explanation? These pages cover the same concepts:

Next: 11.1d — Create PT: Build Day 3

0/3 answered

Answers save on this device as you type. At the end of class, click Download and upload the file to the Canvas assignment.

Saved on this device only — the Dashboard tracks your progress.