Proof of Completion and Running on Open Coding Society Code Runner

Code that was Used in Code Runner with comments explaining
/*
* Scoreboard Class
*
* This class keeps track of a game between two teams. The game works like this:
* - Two teams take turns being the "active" team
* - When a team scores points, those points go to the active team and they keep playing
* - When a play fails (0 points), the turn switches to the other team
* - Team 1 always starts as the active team
*
* The class stores:
* - The names of both teams
* - The current score for each team
* - Which team is currently active (whose turn it is)
*/
class Scoreboard {
// Instance variables to store the state of the game
private String team1Name; // Name of the first team
private String team2Name; // Name of the second team
private int team1Score; // Current score for team 1
private int team2Score; // Current score for team 2
private boolean isTeam1Active; // Tracks whose turn it is - true means team 1 is playing
/*
* Constructor - sets up a new game between two teams
*
* When we create a new Scoreboard, we need to:
* 1. Save both team names so we can display them later
* 2. Set both scores to 0 since the game just started
* 3. Make team 1 the active team (the rules say team 1 always goes first)
*
* Parameters:
* team1Name - the name of the first team (this team starts)
* team2Name - the name of the second team
*/
public Scoreboard(String team1Name, String team2Name) {
this.team1Name = team1Name;
this.team2Name = team2Name;
this.team1Score = 0;
this.team2Score = 0;
this.isTeam1Active = true;
}
/*
* recordPlay - handles what happens when a team makes a play
*
* This method does one of two things depending on the points value:
*
* If points is greater than 0:
* - The active team scored, so we add those points to their total
* - The same team stays active and gets to keep playing
*
* If points equals 0:
* - The play failed, so no points are added
* - The turn ends and we switch to the other team
*
* Parameter:
* points - how many points were scored (0 means the play failed)
*/
public void recordPlay(int points) {
if (points > 0) {
// The play was successful - add points to whichever team is currently active
if (isTeam1Active) {
team1Score += points;
} else {
team2Score += points;
}
// Note: the active team does not change here, they keep playing
} else {
// The play failed - switch which team is active
// Using the not operator to flip the boolean value
isTeam1Active = !isTeam1Active;
}
}
/*
* getScore - returns a string showing the current state of the game
*
* The format is: "team1Score-team2Score-activeTeamName"
* For example: "3-5-Blue" means team 1 has 3 points, team 2 has 5 points,
* and the team named "Blue" is currently active
*
* Returns:
* A formatted string with scores and the name of the active team
*/
public String getScore() {
// Figure out which team name to display as active
String activeTeamName;
if (isTeam1Active) {
activeTeamName = team1Name;
} else {
activeTeamName = team2Name;
}
// Build and return the score string in the required format
return team1Score + "-" + team2Score + "-" + activeTeamName;
}
}
// 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);
}
}
Area of Stuggle
An area of struggle for me is using the correct syntax when writing my class. I will have the correct idea on how to write the correct code, by planning out a pysudocode verison in my head and then thinking about how that would be written in Java. I understand how to write the code but, sometimes I make mistakes with my syntax which happened many times for example forgetting semicolon, incorrect bracket, didn’t indent correctly. These errors caused the code runner to have an error and it allowed me to debug. This is something i should work on fixing and improving, so I get better with avoiding syntax errors on AP Exam.