Sprint View

2024 FRQ 3

2 min read

2024 AP Computer Science A

Free Response Question 3: WordChecker Class


Question 3: WordChecker - ArrayList String Manipulation

This question involves the manipulation and analysis of a list of words. The WordChecker class contains an ArrayList<String> to be analyzed and methods that are used to perform the analysis. You will write two methods of the WordChecker class.

Code Runner Challenge

The WordChecker class contains an ArrayList and methods to analyze word patterns.

Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...

(a) Write the isWordChain method

Write the isWordChain method, which determines whether each element of wordList (except the first) contains the previous element as a substring. The following table shows two sample isWordChain method calls.

wordList isWordChain Return Value Explanation
["an", "band", "band", "abandon"] true Each element contains the previous element as a substring.
["to", "too", "stool", "tools"] false "tools" does not contain the substring "stool".

Complete the isWordChain method:

Code Runner Challenge

Complete the isWordChain method. Return true if each element of wordList (except the first) contains the previous element as a substring, and false otherwise.

Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...

(b) Write the createList method

Write the createList method, which creates and returns an ArrayList<String>. The method identifies strings in wordList that start with target and returns a new ArrayList containing each identified string without the starting occurrence of target. Elements must appear in the returned list in the same order as they appear in wordList.

Consider an example where wordList contains the following strings:

["catch", "bobcat", "catchacat", "cat", "at"]

The following table shows the ArrayList returned by some calls to createList. In all cases, wordList is unchanged.

Method Call ArrayList Returned by createList Explanation
createList("cat") ["ch", "chacat", ""] Only "catch", "catchacat", and "cat" begin with "cat".
createList("catch") ["", "acat"] Only "catch" and "catchacat" begin with "catch".
createList("dog") [] None of the words in wordList begin with "dog".

Write the createList method:

Code Runner Challenge

Complete the createList method. It should return an ArrayList containing strings from wordList that start with target, with the initial occurrence of target removed from each string.

Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...

Course Timeline