← All free-response questionsQuestion 2 · Class Design · 7 points
Rally Scoreboard
Write the complete Scoreboard class, which tracks a volleyball rally game between two teams. The first team to reach the target score wins, and points scored after that are ignored.
| Statement | Value returned | Explanation |
|---|---|---|
Scoreboard s = new Scoreboard("Owls", "Hawks", 3); | The game is played to 3. | |
s.point("Owls") | Owls 1, Hawks 0 | |
s.point("Hawks") | Owls 1, Hawks 1 | |
s.getScore() | "Owls 1 - 1 Hawks" | |
s.getWinner() | "none" | No team has 3 yet. |
s.point("Owls") | Owls 2 | |
s.point("Owls") | Owls 3; Owls win. | |
s.point("Hawks") | Ignored; the game is over. | |
s.getScore() | "Owls 3 - 1 Hawks" | |
s.getWinner() | "Owls" |
Write the complete Scoreboard class. Assume point is always called with one of the two team names.
Your class
7 pointsYour class must have a constructor and the methods point, getScore, and getWinner, and must behave as shown.
Tab inserts spaces. Drafts save as you type.
Self-score
0 / 7