class ScoreBoard {
public static void main(String[] args) {
ScoreBoard game = new ScoreBoard("Red", "Blue");
System.out.println(game.getScore());
game.recordPlay(1);
System.out.println(game.getScore());
game.recordPlay(0);
System.out.println(game.getScore());
System.out.println(game.getScore());
game.recordPlay(3);
System.out.println(game.getScore());
game.recordPlay(1);
game.recordPlay(0);
System.out.println(game.getScore());
game.recordPlay(0);
game.recordPlay(4);
game.recordPlay(0);
System.out.println(game.getScore());
}
private String team1;
private String team2;
private String active;
private int team1Score;
private int team2Score;
public ScoreBoard(String team1, String team2) {
this.team1 = team1;
this.team2 = team2;
active = team1;
team1Score = 0;
team2Score = 0;
}
public void recordPlay(int score) {
if (active.equals(team1)) {
if (score == 0) {
active = team2;
} else {
team1Score += score;
}
} else {
if (score== 0) {
active = team1;
} else {
team2Score += score;
}
}
}
public String getScore() {
return team1Score + "-" + team2Score + "-" + active;
}
}