Computer Science A
Course Progress
0/0
OCS Build and Lesson
Code Runner - Java
Code Runner - Examples
Code Runner - JavaScript
FRQ - Methods and Control Structures
Challenge Submission Test
2021 FRQ 3
2023 FRQ 3
2024 FRQ 3
2024 FRQ 2
2024 FRQ 1
2024 FRQ 4
FRQ 2 - Sign Class
2023 FRQ 1
2021 FRQ 2
2019 FRQ 4
2019 FRQ 2
2019 FRQ 1
2016 FRQ 3
2018 FRQ Question 4
2018 FRQ Question 3
2018 FRQ Question 2
2018 FRQ Question 1
2017 FRQ 4
2017 FRQ 3
2017 FRQ Question 2
2017 FRQ 1
2016 FRQ 4
2016 FRQ 2
2016 FRQ Q1
FRQ - 2D Arrays
FRQ - ArrayLists
2025 FRQ 4
2025 FRQ 3
2025 FRQ 2
2025 FRQ 1
FRQ - Classes
FRQ - Array
2023 FRQ 4
2022 FRQ 4
2022 FRQ 3
2022 FRQ 2
2022 FRQ 1
2021 FRQ 4
2021 FRQ 1
2015 FRQ 4
2015 FRQ 2
2015 FRQ 1
2015 FRQ 3
2014 FRQ Q2 - Writing a Class
2019 FRQ 3
2014 FRQ 1
Sprint View
Week 19
2024 FRQ 2
2024 FRQ 2
5 min read
- FRQ Question
- Use Case Examples
- Code Runner Challenge
- Expected Outputs
FRQ Question
This question involves a scoreboard for a game. The game is played between two teams who alternate turns so that at any given time, one team is active and the other team is inactive. During a turn, a team makes one or more plays. Each play can score one or more points and the team’s turn continues, or the play can fail, in which case no points are scored and the team’s turn ends. The Scoreboard class, which you will write, is used to keep track of the score in a game.
The Scoreboard class contains a constructor and two methods.
- The constructor has two parameters. The first parameter is a String containing the name of team 1, and the second parameter is a String containing the name of team 2. The game always begins with team 1 as the active team.
- The recordPlay method has a single nonnegative integer parameter that is equal to the number of points scored on a play or 0 if the play failed. If the play results in one or more points scored, the active team’s score is updated and that team remains active. If the value of the parameter is 0, the active team’s turn ends and the inactive team becomes the active team. The recordPlay method does not return a value.
- The getScore method has no parameters. The method returns a String containing information about the current state of the game. The returned string begins with the score of team 1, followed by a hyphen (“-“), followed by the score of team 2, followed by a hyphen, followed by the name of the team that is currently active.
Use Case Examples
| Statement | Value Returned (blank if none) | Explanation |
|---|---|---|
String info;Scoreboard game =new Scoreboard("Red", "Blue"); |
game is a new Scoreboard for a game played between team 1, whose name is “Red”, and team 2, whose name is “Blue”. The active team is set to team 1. | |
info = game.getScore(); |
“0-0-Red” | |
game.recordPlay(1); |
Team 1 earns 1 point because the game always begins with team 1 as the active team. | |
info = game.getScore(); |
“1-0-Red” | |
game.recordPlay(0); |
Team 1’s play failed, so team 2 is now active. | |
info = game.getScore(); |
“1-0-Blue” | |
info = game.getScore(); |
“1-0-Blue” | The score and state of the game are unchanged since the last call to getScore. |
game.recordPlay(3); |
Team 2 earns 3 points. | |
info = game.getScore(); |
“1-3-Blue” | |
game.recordPlay(1); |
Team 2 earns 1 point. | |
game.recordPlay(0); |
Team 2’s play failed, so team 1 is now active. | |
info = game.getScore(); |
“1-4-Red” | |
game.recordPlay(0); |
Team 1’s play failed, so team 2 is now active. | |
game.recordPlay(4); |
Team 2 earns 4 points. | |
game.recordPlay(0); |
Team 2’s play failed, so team 1 is now active. | |
info = game.getScore(); |
“1-8-Red” | |
Scoreboard match =new Scoreboard("Lions", "Tigers"); |
match is a new and independent Scoreboard object. | |
info = match.getScore(); |
“0-0-Lions” | |
info = game.getScore(); |
“1-8-Red” |
Code Runner Challenge
Create Your Own Scoreboard Class
View IPYNB Source
// CODE_RUNNER: Create Your Own Scoreboard Class
// Create the Scoreboard Class HERE
class Scoreboard {
// Define your properties HERE
public Scoreboard(String team1Name, String team2Name) {
// This is your CONSTRUCTOR
// Initialize your properties HERE (team names and active team)
}
public void recordPlay(int points) {
// Create the recordPlay Method HERE
}
public String getScore() {
// Create the getScore Method HERE
return ""; // Modify this return statement to return the actual score with the given format
}
}
// Testing the Scoreboard class (DO NOT MODIFY this part unless you change the class, method, or constructer names)
// DO NOT MODIFY BELOW THIS LINE
class Main {
public static void main(String[] args) {
String info;
// Step 1: Create a new Scoreboard for "Red" vs "Blue"
Scoreboard game = new Scoreboard("Red", "Blue");
// Step 2
info = game.getScore(); // "0-0-Red"
System.out.println("(Step 2) info = " + info);
// Step 3
game.recordPlay(1);
// Step 4
info = game.getScore(); // "1-0-Red"
System.out.println("(Step 4) info = " + info);
// Step 5
game.recordPlay(0);
// Step 6
info = game.getScore(); // "1-0-Blue"
System.out.println("(Step 6) info = " + info);
// Step 7 (repeated call to show no change)
info = game.getScore(); // still "1-0-Blue"
System.out.println("(Step 7) info = " + info);
// Step 8
game.recordPlay(3);
// Step 9
info = game.getScore(); // "1-3-Blue"
System.out.println("(Step 9) info = " + info);
// Step 10
game.recordPlay(1);
// Step 11
game.recordPlay(0);
// Step 12
info = game.getScore(); // "1-4-Red"
System.out.println("(Step 12) info = " + info);
// Step 13
game.recordPlay(0);
// Step 14
game.recordPlay(4);
// Step 15
game.recordPlay(0);
// Step 16
info = game.getScore(); // "1-8-Red"
System.out.println("(Step 16) info = " + info);
// Step 17: Create an independent Scoreboard
Scoreboard match = new Scoreboard("Lions", "Tigers");
// Step 18
info = match.getScore(); // "0-0-Lions"
System.out.println("(Step 18) match info = " + info);
// Step 19: Verify the original game is unchanged
info = game.getScore(); // "1-8-Red"
System.out.println("(Step 19) game info = " + info);
}
}
Main.main(null);
Lines: 1
Characters: 0
Output
Click "Run" in code control panel to see output ...
Expected Outputs
| Step | Printed Output |
|---|---|
| Step 2 | (Step 2) info = 0-0-Red |
| Step 4 | (Step 4) info = 1-0-Red |
| Step 6 | (Step 6) info = 1-0-Blue |
| Step 7 | (Step 7) info = 1-0-Blue |
| Step 9 | (Step 9) info = 1-3-Blue |
| Step 12 | (Step 12) info = 1-4-Red |
| Step 16 | (Step 16) info = 1-8-Red |
| Step 18 | (Step 18) match info = 0-0-Lions |
| Step 19 | (Step 19) game info = 1-8-Red |