/* An instance of this class represents the state of a game of tennis. ** ** Authors: R. McCloskey and < STUDENT's NAME > ** Date: Sept. 2026 ** CMPS 144, Fall 2026, Solution to Prog. Assg. #1 */ public class TennisGameState { // An enumerated type whose values refer to the two players in a // game of tennis. public enum Player { SERVER, RECEIVER }; // constants // --------- protected static final int POINTS_TO_WIN = 4; protected static final int MIN_WIN_MARGIN = 2; // instance variables // ------------------ protected int serverPoints; // # points scored by the server protected int receiverPoints; // # points scored by the receiver // constructors // ------------ /* Initializes this game state to be one in which no points have been ** scored. */ public TennisGameState() { // STUB } // observers // --------- // Returns # of points scored in this game by the server. public int getServerPoints() { return serverPoints; } // Returns # of points scored in this game by the receiver. public int getReceiverPoints() { return -1; } // STUB /* Returns true iff the server has won the game. */ public boolean serverHasWon() { return false; // STUB } /* Returns true iff the receiver has won the game. */ public boolean receiverHasWon() { return false; // STUB } /* Returns either SERVER, RECEIVER, or null, according to whether this ** game was won by the server, the receiver, or neither, respectively. */ public Player winner() { if (serverHasWon()) { return Player.SERVER; } else if (receiverHasWon()) { return Player.RECEIVER; } else { return null; } } /* Returns true if the game is over, false otherwise. ** The game is over if one player or the other has won the game. */ public boolean isOver() { return false; // STUB } /* Returns true iff the game is "at deuce", which occurs when the ** two players have scored the same number of points and that number ** is at least POINTS_TO_WIN - 1. */ public boolean isDeuce() { return false; // STUB } /* Returns true iff the game is in an "advantage server" situation. */ public boolean serverHasAdvantage() { return false; // STUB } /* Returns true iff the game is in an "advantage receiver" situation. */ public boolean receiverHasAdvantage() { return false; // STUB } /* Returns true iff the game is in an "advantage" situation, meaning ** one in which one player has scored at least POINTS_TO_WIN points ** and the opponent has scored exactly one fewer point. */ public boolean isAdvantage() { return serverHasAdvantage() || receiverHasAdvantage(); } /* Returns either SERVER, RECEIVER, or null, according to which player, ** if either, is in an "advantage" situation. */ public Player advantageHolder() { if (serverHasAdvantage()) { return Player.SERVER; } else if (receiverHasAdvantage()) { return Player.RECEIVER; } else { return null; } } /* Returns a string of the form "k - m", where k is the number of ** points scored by the server and m is the number of points scored ** by the receiver. */ public String getScore() { return getServerPoints() + " - " + getReceiverPoints(); } public String toString() { StringBuilder result = new StringBuilder(getScore()); if (isDeuce()) { result.append(" (Deuce)"); } else if (isAdvantage()) { result.append(" (Advantage " + advantageHolder() + ')'); } else if (isOver()) { result.append(" (Game " + winner() + ')'); } else { } return result.toString(); } // mutators // -------- /* Records a point being scored by the server. ** precondition: Prior to the point being scored, the game was not over. */ public void pointForServer() { // STUB } /* Records a point being scored by the receiver. ** precondition: Prior to the point being scored, the game was not over. */ public void pointForReceiver() { // STUB } // private utility methods // ----------------------- }