2024 AP CSA FRQ 2: Scoreboard - Complete Solution
Share
2024 AP CSA FRQ 2: Scoreboard
Topic: Class Design & Game State
Skills: Instance variables, state management
Unit: Unit 3 (Class Creation) | Points: 9
Study Guide: Unit 3: Class Creation
Part (a)
Write Scoreboard class.
Try it first!
public class Scoreboard {
private String team1, team2;
private int score1, score2;
private boolean team1Active;
public Scoreboard(String team1, String team2) {
this.team1 = team1; this.team2 = team2;
score1 = 0; score2 = 0; team1Active = true;
}
public void recordPlay(int points) {
if (points > 0) {
if (team1Active) {
score1 += points;
}
else {
score2 += points;
}
} else {
team1Active = !team1Active;
}
}
public String getScore() {
return score1 + "-" + score2;
}
}Part (b)
Track scores and active team.
// points > 0: add to active team
// points == 0: switch active teamKey Concepts
- Boolean for active team
- Only add positive points
- Switch on 0 points
Common Mistakes
- Wrong team gets points
- Not switching correctly
Author: Tanner Crow, AP CS Teacher (11+ years)