2024 FRQ 2 Homework
Code Written
/*
*Creates and keeps track of a game between two teams
*Gameplay:
*- Teams take turns scoring points
*- If teams score no points, it becomes the other team's turn to score
*- Team 1 is always the starting team
*
*Scoreboard stores the team names, the active team, and the scores of each team
*/
class Scoreboard {
private String team1Name;
private String team2Name;
private String activeTeam;
private Integer team1Score;
private Integer team2Score;
/*
*Constructor of each game
*2 parameters, one for each team name
*Both parameters are strings
*/
public Scoreboard(String team1, String team2) {
team1Name = team1;
team2Name = team2;
activeTeam = team1;
team1Score = 0;
team2Score = 0;
}
/*
*recordPlay updates variables when a team makes a play
*
* If pointsScored is 0:
* - swaps active team
* - checks which team is active
* - changes activeTeam to the other team
*
* If pointsScored is greater than 0:
* - adds point total to active team
*/
public void recordPlay(Integer pointsScored) {
if (pointsScored == 0) {
if (activeTeam.equals(team1Name)) {
activeTeam = team2Name;
}
else {
activeTeam = team1Name;
}
}
else {
if (activeTeam.equals(team1Name)) {
team1Score += pointsScored;
}
else {
team2Score += pointsScored;
}
}
}
/*
*Returns a string with both team's scores and the active team
*The format is team1Score-team2Score-activeTeam
*/
public String getScore() {
return team1Score + "-" + team2Score + "-" + activeTeam;
}
}
public class Main {
public static void main(String[] args) {
String info;
Scoreboard game = new Scoreboard("Red", "Blue");
info = game.getScore();
System.out.println(info);
game.recordPlay(1);
info = game.getScore();
System.out.println(info);
game.recordPlay(0);
info = game.getScore();
System.out.println(info);
info = game.getScore();
System.out.println(info);
game.recordPlay(3);
info = game.getScore();
System.out.println(info);
game.recordPlay(1);
game.recordPlay(0);
info = game.getScore();
System.out.println(info);
game.recordPlay(0);
game.recordPlay(4);
game.recordPlay(0);
info = game.getScore();
System.out.println(info);
Scoreboard match = new Scoreboard("Lions", "Tigers");
info = match.getScore();
System.out.println(info);
info = game.getScore();
System.out.println(info);
}
}
Proof of Success

Code Explanation
Scoreboard Class
Defined initial variables necessary (team names, active team, team scores).
Scoreboard Constructor
Basic constructor that has team names as parameters, constructs scoreboard with team names, active team, and team scores.
recordPlay Method
Checks if points scored == 0, if they are then checks for which team is active and sets the other one to be active. If points scored aren’t 0, adds points scored to active team.
getScores Method
Returns a string containing each team’s scores and the active team.
Main Class and Method
Constructs scoreboards and runs tests to ensure each part works according to requirements.
Areas of Struggle
I have a couple of areas of struggle, though fairly small and simple to fix. The first is that I get sort of confused on when a class should be private, public, or neither, and that was causing errors for a while when I was trying to run my code becuase there were multiple publics or a class was incorrectly private, etc. The second thing that I struggle with is syntax, as I am not used to coding in java too much and so I don’t do proper syntax on occasion. The last thing that I struggle with is variable typing, where I sometimes forget to give variables a type and that causes errors as you can imagine.