AP CSA 2015 FRQ 4 Numbergroup

FRQ Archive2015 FRQs › FRQ 4: NumberGroup
2015 AP CSA • Interface Implementation

AP CSA 2015 FRQ 4: NumberGroup

Classic Exam Note: This FRQ requires writing classes that implement the NumberGroup interface. Interface implementation is no longer tested on the current AP CSA exam.

Complete solution, scoring rubric, and walkthrough — verified from the official College Board PDF

9 Points Hard Interface Implementation Classic Format (Pre-2019)
Question Type Interface Implementation
Key Skills Write a Range class implementing the NumberGroup interface (contains() checks if a value is within min..max bounds), the
Difficulty Hard
AP CSA Units Unit 3: Class Creation (interface implementation, class design) and Unit 4 (ArrayList of interface-typed objects, composite delegation).

What This Problem Asks

Write a Range class implementing the NumberGroup interface (contains() checks if a value is within min..max bounds), then write MultipleGroups (holds an ArrayList of NumberGroup objects; contains() returns true if any sub-group contains the value).

Official Question & PDF

Download Full 2015 FRQ PDF →

PDF cannot display here. Open PDF directly →

Provided Code

public interface NumberGroup
{
    boolean contains(int number);
}

// Write the Range class:
// Range(int min, int max) — stores bounds
// contains(int number) — true if min <= number <= max

// Write the MultipleGroups class:
// MultipleGroups(ArrayList groups) — stores groups
// contains(int number) — true if ANY group contains number
Timer 22:00

Part A — Range class (4 Points)

Write the Range class that implements NumberGroup. Its constructor takes min and max (inclusive bounds); contains() returns true if number is within the range.

Drag corner to expand ▽

 

Scoring Rubric

+1 Declares class with implements NumberGroup
+1 Constructor stores min and max in instance variables
+1 contains() checks number >= min
+1 contains() checks number <= max and returns correct boolean

Solution

public class Range implements NumberGroup
{
    private int minVal;
    private int maxVal;

    public Range(int min, int max)
    {
        minVal = min;
        maxVal = max;
    }

    public boolean contains(int number)
    {
        return number >= minVal && number <= maxVal;
    }
}
Simple range check. Both bounds are INCLUSIVE (>= and <=). Declare implements NumberGroup in the class header.

Part B — MultipleGroups class (5 Points)

Write the MultipleGroups class that implements NumberGroup. Its constructor takes an ArrayList of NumberGroup objects; contains() returns true if any group in the list contains the number.

Drag corner to expand ▽

 

Scoring Rubric

+1 Declares class with implements NumberGroup
+1 Constructor stores the ArrayList of NumberGroup objects
+1 contains() iterates over all groups
+1 contains() calls contains() on each group
+1 Returns true if any group contains the number, false otherwise (algorithm)

Solution

public class MultipleGroups implements NumberGroup
{
    private ArrayList groupList;

    public MultipleGroups(ArrayList groups)
    {
        groupList = groups;
    }

    public boolean contains(int number)
    {
        for (NumberGroup g : groupList)
        {
            if (g.contains(number))
                return true;
        }
        return false;
    }
}
The composite pattern: MultipleGroups delegates contains() to each sub-group. Return true immediately when any group matches; return false only after checking all groups.

Common Mistakes to Avoid

Using strict inequality in Range.contains()

Wrong

return number > minVal && number < maxVal; // excludes boundary values

Correct

return number >= minVal && number <= maxVal; // inclusive bounds

The problem specifies INCLUSIVE bounds. A value equal to min or max IS in the range.

Not implementing NumberGroup in the class declaration

Wrong

public class Range { ... } // missing implements

Correct

public class Range implements NumberGroup { ... }

Both Range and MultipleGroups must declare implements NumberGroup. Without it they do not satisfy the interface and cannot be stored in an ArrayList.

Exam Tips

Interface implementation is no longer on the current AP CSA exam, but the composite pattern here — an object that holds a list of same-typed objects and delegates a method call to each — is a useful design pattern to understand.
Return true early in MultipleGroups.contains() — no need to check remaining groups once a match is found.

Frequently Asked Questions

What does 2015 AP CSA FRQ 4 NumberGroup ask?

It asks students to write the Range class (implements NumberGroup with inclusive bounds check) and the MultipleGroups class (implements NumberGroup by delegating contains() to a list of NumberGroup objects, returning true if any sub-group matches).

Is interface implementation still tested on the current AP CSA exam?

No. Interfaces and the implements keyword were removed from the AP CSA curriculum in the 2019 redesign. The composite delegation pattern in MultipleGroups is algorithmically interesting but not directly testable on the current exam.

See All 2015 AP CSA FRQs

View the complete 2015 exam hub with solutions, difficulty analysis, and scoring for all four questions.

View 2015 FRQ Hub →

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]