2014 SCORING COMMENTARY
AP
Question 1
Overview
This question asked the students to write two static methods for an unnamed class which had no instance
variables. The question involved using methods of the String class (to get individual letters of the
String and to build a new String) and methods of the List interface (to access elements of the
List and to modify an existing List). In part (a), the students were required to implement a static
method called scrambleWord to scramble a String parameter (word) by reversing pairs of
adjacent letters of word whenever the pair consisted of "A" followed by a letter that was not "A". The
students needed to access all letters in word from left to right, identifying the pairs of letters to be
swapped. The identified pair could be reversed by rebuilding word or by constructing a new result
String. All letters of word that were not involved in reversals were to be in their original positions in
the result String, which was then returned by the method. In part (b), the students were required to
implement a static method called scrambleOrRemove. The method had a List parameter
(wordList) in which each element was a String of letters. The students needed to access each word
in wordList, to correctly call the scrambleWord method of part (a) with the word as the argument,
and to determine whether the word had been changed by scrambling. Upon exiting
scrambleOrRemove, wordList was to contain only words changed by scrambleWord in their
scrambled form. If the word had been scrambled by scrambleWord, the word was replaced in
wordList by the scrambled version of the word. If the word was unchanged by scrambleWord, the
word removed from wordList.
Note: This question involves static methods of a class having no instance variables. The use of
this.scrambleWord or this.anything is incorrect in this question.
Sample: 1A
Score: 8
In part (a) the student correctly accesses all letters in word, looping through all one-letter substrings of
word. The
student correctly identifies all substrings equal to “A” and correctly identifies when the next
substring is not “A”.
The student correctly reverses all pairs of substrings consisting of “A” followed by not “A” by constructing
a new
result string. The student correctly builds the result string, reversing pairs of letters when necessary
and avoids using each “A” in more than one swap by incrementing the loop index an extra time after each
reversal is made. After the loop, the student concatenates the last letter of word to the result string.
However, this is not the correct thing to do in all cases. When the last letter of word is used in a reversal,
it has already been put into the result string and would be duplicated by this assignment. Therefore, the
student does not earn the point for constructing the correct result string. The result string is correctly
returned. The response earned 4 points for part (a).
In part (b) the student correctly accesses all words in wordList using a for-loop. After the remove
meth
od call, the student decrements the index so that no words are skipped.
The student correctly calls the scrambleWord method using a word from wordList as a parameter.
The scrambled word is correctly compared with the original word. If the word is not changed by
scrambleWord, the word is removed from wordList. Otherwise the word is replaced by the result of
scrambling the word. The response earned 4 points in part (b).
© 2014 The College Board.
Visit the College Board on the Web: www.collegeboard.org.
®
COMPUTER SCIENCE A