2024 AP CSA FRQ 3: WordChecker - Complete Solution

2024 AP CSA FRQ 3: WordChecker

Topic: String Analysis

Skills: Substring comparison, grouping check

Unit: Unit 2 (Selection/Iteration) | Points: 9

Part (a)

Write isWordChain.

Try it first!
public boolean isWordChain() {
    for (int i = 0; i < wordList.size() - 1; i++) {
        String current = wordList.get(i);
        String next = wordList.get(i + 1);
        if (next.indexOf(current) != 0) {
            return false;
        }
    }
    return true;
}

Part (b)

Write createList.

public ArrayList createList(String target) {
    ArrayList result = new ArrayList();
    for (String word : wordList) {
        if (target.indexOf(word) == 0) {
            result.add(word);
        }
        else if (word.indexOf(target) == 0) {
            result.add(word);
        }
    }
    return result;
}

Key Concepts

  • indexOf == 0 means starts with
  • Check both directions
  • Chain: each word starts with previous

Common Mistakes

  • indexOf != 0 vs indexOf == -1
  • Missing one direction check

Author: Tanner Crow, AP CS Teacher (11+ years)

Back to blog

Leave a comment

Please note, comments need to be approved before they are published.