MessageBuilder
is #1 from the from the 2025 AP Computer Science A Course Description sample problems.
2025 AP CS A Course Description
The sample free response start on PDF page 168 (labeled page 161 at the bottom right).
Part (a) MessageBuilder
constructor
public MessageBuilder(String startingWord)
{
message = startingWord;
numWords = 1;
String nextWord = getNextWord(startingWord);
while(nextWord != null)
{
message += " " + nextWord;
numWords++;
nextWord = getNextWord(nextWord);
}
}
Part (b) getAbbreviation
method
public String getAbbreviation()
{
String abbreviation = "";
for(String word : message.split(" "))
abbreviation += word.substring(0, 1);
return abbreviation;
}
Java files with test code
MessageBuilderTester.java includes JUnit 5 test code with the examples from the problem. See Running JUnit 5 tests. MessageBuilder.java includes a working implementation of getNextWord
. The getNextWord
implementation throws an exception if passed a word other than the immediately preceeding word in the sequence.
MessageBuilder.java
MessageBuilderTester.java
2025 AP CS A Course Description Free Response Solutions
- CupcakeMachine Free Response Solution
- ItemInventory Free Response Solution
- Schedule Free Response Solution
Help & comments
Get help from AP CS Tutor Brandon Horn
See an error? Question? Please comment below.