```java public class Scoreboard { // Instance variable to store the name of team 1 private String team1Name;

// Instance variable to store the name of team 2
private String team2Name;

// Instance variable to store the score of team 1
private int team1Score;

// Instance variable to store the score of team 2
private int team2Score;

// Instance variable to track which team is currently active (true = team 1, false = team 2)
private boolean team1Active;

/**
 * Constructor: Initializes a new Scoreboard with two team names
 * @param team1 - the name of team 1
 * @param team2 - the name of team 2
 */
public Scoreboard(String team1, String team2) {
    // Set the name of team 1
    team1Name = team1;
    
    // Set the name of team 2
    team2Name = team2;
    
    // Initialize team 1's score to 0
    team1Score = 0;
    
    // Initialize team 2's score to 0
    team2Score = 0;
    
    // Set team 1 as the active team (game always starts with team 1)
    team1Active = true;
}

/**
 * Records a play in the game
 * @param points - the number of points scored (0 means the play failed)
 */
public void recordPlay(int points) {
    // Check if the play failed (points equals 0)
    if (points == 0) {
        // Switch the active team (if team 1 was active, make team 2 active, and vice versa)
        team1Active = !team1Active;
    } else {
        // The play was successful, so add points to the active team's score
        
        // Check if team 1 is the active team
        if (team1Active) {
            // Add the points to team 1's score
            team1Score += points;
        } else {
            // Team 2 is active, so add the points to team 2's score
            team2Score += points;
        }
    }
}

/**
 * Returns the current game state as a formatted string
 * @return a String in the format "team1Score-team2Score-activeTeamName"
 */
public String getScore() {
    // Declare a variable to hold the name of the active team
    String activeTeam;
    
    // Check if team 1 is the active team
    if (team1Active) {
        // Set activeTeam to team 1's name
        activeTeam = team1Name;
    } else {
        // Set activeTeam to team 2's name
        activeTeam = team2Name;
    }
    
    // Return the formatted string: "score1-score2-activeTeamName"
    return team1Score + "-" + team2Score + "-" + activeTeam;
}

/**
 * Main method for testing the Scoreboard class
 */
public static void main(String[] args) {
    // Declare a variable to store the result of getScore() calls
    String info;
    
    // Create a new Scoreboard for a game between "Red" and "Blue"
    Scoreboard game = new Scoreboard("Red", "Blue");
    
    // Get the initial score (should be "0-0-Red")
    info = game.getScore();
    System.out.println(info); // Expected: "0-0-Red"
    
    // Team 1 (Red) scores 1 point
    game.recordPlay(1);
    info = game.getScore();
    System.out.println(info); // Expected: "1-0-Red"
    
    // Team 1's play fails (0 points), so team 2 becomes active
    game.recordPlay(0);
    info = game.getScore();
    System.out.println(info); // Expected: "1-0-Blue"
    
    // Team 2 (Blue) scores 3 points
    game.recordPlay(3);
    info = game.getScore();
    System.out.println(info); // Expected: "1-3-Blue"
    
    // Team 2 (Blue) scores 1 point
    game.recordPlay(1);
    
    // Team 2's play fails (0 points), so team 1 becomes active again
    game.recordPlay(0);
    info = game.getScore();
    System.out.println(info); // Expected: "1-4-Red"
    
    // Team 1's play fails (0 points), so team 2 becomes active
    game.recordPlay(0);
    
    // Team 2 (Blue) scores 4 points
    game.recordPlay(4);
    
    // Team 2's play fails (0 points), so team 1 becomes active again
    game.recordPlay(0);
    info = game.getScore();
    System.out.println(info); // Expected: "1-8-Red"
    
    // Create a new, independent Scoreboard for a game between "Lions" and "Tigers"
    Scoreboard match = new Scoreboard("Lions", "Tigers");
    info = match.getScore();
    System.out.println(info); // Expected: "0-0-Lions"
    
    // Verify that the original game object is unchanged
    info = game.getScore();
    System.out.println(info); // Expected: "1-8-Red"
} }

Evidence

frq proof

Struggles

Getting the syntax right was the hardest part. I kept mixing up when to use dot notation versus brackets, and my loops weren’t iterating the way I expected. After stepping through the code manually and checking the API docs, it clicked. Once I understood how the data structures were actually organized, the rest came together pretty quickly.

😊