/* An instance of this class represents the state of a game of tennis. ** It enhances its parent class in two respects: ** (1) A name can be associated to each player (e.g., "Borg", "Gauff"), ** and the string produced by the toString() method (which overrides ** the inherited version) mentions those names. ** (2) The getScore() method (which overrides the inherited version) ** produces a string that describes the score of the game in accord ** with the conventions of tennis (e.g., so that a score of 3-2 is ** translated into "40-30" and 0-2 is translated into "LOVE-30"). ** ** Authors: R. McCloskey and < STUDENT's NAME > ** Date: Sept. 2026 ** CMPS 144, Fall 2026, Solution to Prog. Assg. #2 ** Collaborated with: ... ** Known Defects: ... */ public class TennisGameState2 extends TennisGameState { // instance variables // ------------------ protected String serverName; protected String receiverName; // constructors // ------------ /* Initializes this game state to be one in which no points have been ** scored and in which the two players have the specified names. */ public TennisGameState2(String nameOfServer, String nameOfReceiver) { // STUB } /* Initializes this game state to be one in which no points have been ** scored and in which the two players have generic names. */ public TennisGameState2() { this("Server", "Receiver"); // calls the other constructor } // observers // --------- /* Methods to return the names of the server and receiver, respectively. */ public String getServerName() { return serverName; } public String getReceiverName() { return receiverName; } /* Returns a String describing the current score of the game. ** Depending upon the score, the String should have one of five forms ** as exemplified by what is shown below, where it is assumed that one ** of the players is named "Borg" (as in Bjorn Borg, Sweden's 11-time ** major champion): ** ** "GAME Borg" ** "ADVANTAGE Borg" ** "DEUCE" ** "15 - 40", "30 - LOVE" ** "30 ALL" */ @Override public String getScore() { return "Glorp"; // STUB } /* Returns a String describing the state of the game. The first part ** of the string identifies the server and the receiver by name and ** indicates how many points each has scored during the game. ** The second part is the game's score as expressed by the getScore() ** method. Here are a few examples: ** ** "Connors(5) serving Borg(6): ADVANTAGE Borg" ** "Clijsters(2) serving Sharapova(0): 30 - LOVE" */ @Override public String toString() { String prefix = getServerName() + '(' + getServerPoints() + ") serving " + getReceiverName() + '(' + getReceiverPoints() + "): "; return prefix + getScore(); } // private methods // --------------- /* Translates the given number of points to what it is called in a tennis ** game's score. The pre-condition is that 0 <= points <= 3. ** Note that this method is "brittle" in that it depends upon the ** POINTS_TO_WIN constant in the parent class having value 4. */ private String pointsInTennisLingo(int points) { // STUB String result = "Glorp"; return result; } }