Skip to main content

AP CSA FRQ Guide

2008 FRQ 4: Checker

Implement substring and conjunction checkers, then combine the supplied checker objects to accept text containing neither of two forbidden substrings.

Legacy Interfaces and Boolean Composition22 minute targetclass writingStringinterfacesboolean logiclegacy

Skills Tested

What this FRQ is really practicing

class writingStringinterfacesboolean logiclegacy

Review these topics before attempting the problem.

Starter Approach

How to begin with your own plan

  1. 1Part A: implement SubstringChecker with a constructor that stores a substring and an accept method that performs a case-sensitive containment check.
  2. 2Part B: implement AndChecker with two stored Checker objects; accept text only when both underlying checkers accept it.
  3. 3Part C: combine aChecker, kChecker, AndChecker, and NotChecker so yummyChecker accepts neither artichokes nor kale.

Attempt the problem before opening the solution.

Common Mistakes

Mistakes to watch for while writing

Using equality instead of case-sensitive substring containment.
Accepting when either checker passes instead of requiring both.
Negating the conjunction of the forbidden checkers, which still allows one forbidden substring.

Self Check

Review questions before you submit

Declares classes implementing the Checker interface.

Both written classes must provide public boolean accept(String text).

Tests substring containment in accept.

Use indexOf or contains without changing case.

Combines the underlying checker results with AND.

Delegate to both stored checker objects.

Composes the provided checker objects for the neither condition.

Negate each forbidden-substring checker, then combine them with AndChecker.

Practice Links

Where to go next