AP CSA · Today's Warm-Up

Returning a boolean, on purpose

You're ahead of schedule this week, which means today's a chance to build real reps instead of busywork. Same CodingBat you'll use all year — today we're just being deliberate about one specific skill: methods that return true or false.

⚙️ One-time setup — do this first

Link your account so I can see your work

This only takes 30 seconds and you only ever do it once. CodingBat only shows me your progress if you share it with me directly — I can't see it otherwise.

  1. Log in to CodingBat (create an account first if you don't have one yet).
  2. Click prefs in the top-right corner.
  3. In the Teacher Share field, enter edwiessmann@philasd.org and click Share.
  4. While you're there, put your name in the Name field too — it's a lot faster for me to find you in the report than hunting through raw email addresses.

Only do this once — it stays linked for every problem you ever do on CodingBat, not just today's.

STEP 1
~10 min

Read through how boolean methods actually work, plus a quick note on the % operator.

STEP 2
~10 min

Run the quick predict-the-output check below to make sure the pattern actually clicked.

STEP 3
~35-40 min

Go to CodingBat and clear the 13 boolean problems checked off below. One green check, move on.

How a boolean method actually works

A method declared boolean has exactly one job: hand back true or false. Nothing else compiles. There are two ways to do that — one is safer to reason about, the other is what you should be reaching for by the end of today.

Works fine — start here
public boolean isPositive(int n) {
    if (n > 0) {
        return true;
    } else {
        return false;
    }
}
Better — aim for this
public boolean isPositive(int n) {
    return n > 0;
}

The trick: n > 0 is already a boolean expression — it evaluates to true or false all on its own. You don't need an if/else to "convert" it into one. Just hand it back directly.

Quick note: the % operator

A few of today's problems use % ("mod"). For now, all you need is this: n % 2 == 0 means n is even, and n % 2 == 1 means n is odd. You'll see it used with other numbers too, like %3 or %10 — same idea. We'll dig into why it actually works later.

Quick check — predict the boolean

Five short ones. Click what you think each one returns before you head to CodingBat.

Today's list — 13 problems, all boolean, no strings yet

Every problem below returns boolean and only uses numbers or booleans — no strings, since we haven't covered those yet. Check them off as you go; it's saved automatically if you close the tab.

Progress 0 / 16