Round
is #3 from the from the 2025 AP Computer Science A Free Response problems.
https://apcentral.collegeboard.org/media/pdf/ap25-frq-computer-science-a.pdf
Part (a) Round
constructor
public Round(String[] names)
{
competitorList = new ArrayList<Competitor>();
for(int i = 0; i < names.length; i++)
competitorList.add(new Competitor(names[i], i + 1));
}
The first line, in which the instance variable competitorList
is initialized, is often written incorrectly (ex: ArrayList<Competitor> competitorList = ...
) or missed entirely. Initializing the instance variable to point to a new ArrayList
is different than adding values to the list.
Part (b) buildMatches
method
public ArrayList<Match> buildMatches()
{
ArrayList<Match> matches = new ArrayList<Match>();
int bestIndex = competitorList.size() % 2;
int worstIndex = competitorList.size() - 1;
while(bestIndex < worstIndex)
{
matches.add(new Match(
competitorList.get(bestIndex),
competitorList.get(worstIndex)));
bestIndex++;
worstIndex--;
}
return matches;
}
Java files with test code
Competitor.java
Match.java
Round.java
ThreeTest.java
2025 AP CS Exam Free Response Solutions
- DogWalker Free Response Solution
- SignedText Free Response Solution
- SumOrSameGame Free Response Solution
Help & comments
Get help from AP CS Tutor Brandon Horn
See an error? Question? Please comment below.
2025-05-09 comment
(Email withheld)
for this question on Part B, instead of while loop (which now I feel like is a way better solution), on the test I used a nested for loop solution something like this (dont remember the whole thing):
for (int i = start; i < competitorList.size(); i++) {
for (int j = competitorList.size() - 1; j > i; j--) {
if (i == j) {
return list;
};
// Match logic
}
}
Do u think it will give me some credit or am I cooked? Btw, thank you so much for providing solutions!
Response
Assuming your comment // Match logic
is where you’re making a Match
object and adding it to the list: You are adding way too many Match
objects to the list. Each competitor, potentially excluding the first, is supposed to be paired up with one other competitor, not all other competitors.
Your approach (though in a different order) is more appropriate for something like WordPairList (2018 #2) in which each word is paired with more than one additional word.
Thanks for reaching out.