AP CSA 2016 FRQ 1 Randomstringchooser

FRQ Archive2016 FRQs › FRQ 1: RandomStringChooser
2016 AP CSA • Class Writing

AP CSA 2016 FRQ 1: RandomStringChooser

Classic Exam Note: Part B uses extends and super(), which are no longer tested on the current AP CSA exam. Part A is fully applicable today.

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

9 Points Medium Class Writing Classic Format (Pre-2019)
Question Type Class Writing
Key Skills Write the complete RandomStringChooser class (stores strings in an ArrayList, removes one randomly via getNext(), return
Difficulty Medium
AP CSA Units Unit 3: Class Creation (complete class), Unit 4: Data Collections (ArrayList with random removal).

What This Problem Asks

Write the complete RandomStringChooser class (stores strings in an ArrayList, removes one randomly via getNext(), returns 'NONE' when empty), then write the RandomLetterChooser subclass constructor using super() and getSingleLetters().

Official Question & PDF

Download Full 2016 FRQ PDF →

PDF cannot display here. Open PDF directly →

Provided Code

// Part A: write entire RandomStringChooser class
// Part B: given skeleton:
public class RandomLetterChooser extends RandomStringChooser
{
    public RandomLetterChooser(String str)
    { /* to be implemented in part (b) */ }

    public static String[] getSingleLetters(String str)
    { /* provided — splits str into array of 1-char strings */ }
}
Timer 22:00

Part A — RandomStringChooser class (7 Points)

Write the entire RandomStringChooser class: constructor takes a String array and populates an ArrayList; getNext() picks and removes a random element, returning 'NONE' if empty.

Drag corner to expand ▽

 

Scoring Rubric

+1 Declares ArrayList instance variable
+1 Constructor populates ArrayList from array parameter
+1 Constructor does not modify the original array
+1 getNext() returns 'NONE' when list is empty
+1 getNext() generates a valid random index
+1 getNext() removes the selected element
+1 getNext() returns the selected string (algorithm)

Solution

public class RandomStringChooser
{
    private ArrayList words;

    public RandomStringChooser(String[] wordArray)
    {
        words = new ArrayList();
        for (String w : wordArray)
        {
            words.add(w);
        }
    }

    public String getNext()
    {
        if (words.isEmpty())
            return "NONE";

        int index = (int)(Math.random() * words.size());
        return words.remove(index);
    }
}
remove(int index) both removes the element AND returns it — use it directly as the return value. Never modify the constructor's array parameter.

Part B — RandomLetterChooser subclass (2 Points)

Write the RandomLetterChooser constructor. It receives a String of letters and must call the parent constructor with getSingleLetters(str).

Drag corner to expand ▽

 

Scoring Rubric

+1 Calls super() with getSingleLetters(str)
+1 super() is the first statement in the constructor

Solution

public RandomLetterChooser(String str)
{
    super(getSingleLetters(str));
}
This is a one-line constructor: super() must be the first statement, and getSingleLetters(str) provides the String array the parent constructor needs.

Common Mistakes to Avoid

Modifying the original array in the constructor

Wrong

words = Arrays.asList(wordArray); // shares backing array

Correct

for (String w : wordArray) { words.add(w); } // copy to new ArrayList

The problem specifies the constructor must not alter the parameter array. Copy elements into a new ArrayList individually.

Using Math.random() without casting to int

Wrong

int index = Math.random() * words.size(); // compile error

Correct

int index = (int)(Math.random() * words.size()); // correct

Math.random() returns a double. It must be cast to int for use as a list index. Alternatively, use (int)(Math.random() * words.size()).

Exam Tips

Part B is worth only 2 points but is free credit — just one line: super(getSingleLetters(str));
Note: inheritance with extends/super is no longer on the current AP CSA exam. Focus on Part A's ArrayList construction for current exam prep.

Frequently Asked Questions

What does 2016 AP CSA FRQ 1 RandomStringChooser ask?

Part A asks students to write the complete RandomStringChooser class with an ArrayList constructor and a getNext() method that picks and removes a random element (returning 'NONE' when empty). Part B asks for a subclass constructor using super().

Is the RandomLetterChooser subclass relevant to the current exam?

No. The subclass part uses extends and super(), which are no longer part of the AP CSA curriculum. Part A (the base class) is directly applicable — ArrayList construction and random removal are tested on every current exam.

See All 2016 AP CSA FRQs

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

View 2016 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]