2008 AP CSA FRQ 4: Checker - Solution

2008 AP CSA FRQ 4: Checker

Topic: Interfaces & Polymorphism

Skills: Interface implementation, boolean logic, composite patterns, NOT logic

Unit: Unit 3 (Class Creation) (2025-2026 AP CSA)

Points: 9 | Time: ~22 minutes

Study Guide: Unit 3: Class Creation

Part (a)

Write the complete SubstringChecker class that implements Checker.

Try First! Attempt before viewing solution.

Solution

public class SubstringChecker implements Checker
{
    private String target;
    
    public SubstringChecker(String target)
    {
        this.target = target;
    }
    
    public boolean accept(String text)
    {
        return text.indexOf(target) >= 0;
    }
}

Part (b)

Write the complete NotChecker class that negates another Checker.

Solution

public class NotChecker implements Checker
{
    private Checker checker;
    
    public NotChecker(Checker checker)
    {
        this.checker = checker;
    }
    
    public boolean accept(String text)
    {
        return !checker.accept(text);
    }
}

Key Concepts

✓ implements keyword for interfaces
✓ Composition: wrapping one Checker in another
✓ indexOf returns -1 if not found, >= 0 if found
✓ Decorator pattern with NotChecker

Common Mistakes

Forgetting implements Checker
Using == instead of >= for indexOf check
Not storing the Checker reference in NotChecker
Forgetting to negate the result in NotChecker
Practice Similar: 2019 FRQ 2 | 2022 FRQ 2 | 2023 FRQ 2

Official Resources

Author: Tanner Crow - AP CS Teacher, 11+ years

Get in Touch

Whether you're a student, parent, or teacher — I'd love to hear from you.

Just want free AP CS resources?

Enter your email below and check the subscribe box — no message needed. Students get daily practice questions and study tips. Teachers get curriculum resources and teaching strategies.

Typically responds within 24 hours

Message Sent!

Thanks for reaching out. I'll get back to you within 24 hours.

🏫 Welcome, fellow educator!

I offer curriculum resources, practice materials, and study guides designed for AP CS teachers. Let me know what you're looking for — whether it's classroom materials, a guest speaker, or Teachers Pay Teachers resources.

Email

[email protected]

📚

Courses

AP CSA, CSP, & Cybersecurity

Response Time

Within 24 hours

Prefer email? Reach me directly at [email protected]