/* An instance of this class represents the score of a game of tennis. */ public class TennisGameScore { // constant // -------- private static final int POINTS_TO_WIN = 4; // instance variables private String serverName, receiverName; // names of the players private int serverPoints, receiverPoints; // # points scored by the players // constructors // ------------ /* Initializes a newly created object and assigns the specified names ** (e.g., "Borg" and "Connors") to the server and receiver, respectively. */ public TennisGameScore(String nameOfServer, String nameOfReceiver) { // STUB!! } /* Initializes a newly created object and assigns the generic names ** "Server" and "Receiver" to the server and receiver, respectively. */ public TennisGameScore() { this("Server", "Receiver"); } // 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 the name of the server. public String getServerName() { return "Glork"; // STUB!! } // Returns the name of the receiver. public String getReceiverName() { return "Snerd"; // STUB!! } /** Returns true if the game is over, false otherwise. ** The game is over if it has been won by either the server or ** the receiver. */ public boolean isOver() { return false; // STUB!! } /* 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's below, where it is assumed that one of ** the sides is named "Borg" (as in Bjorn Borg, Sweden's 11-time ** major champion): ** ** "GAME Borg" ** "ADVANTAGE Borg" ** "DEUCE" ** "15 - 40" ** "30 ALL" */ public String getScore() { return "ADVANTAGE Glork"; // 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" */ public String toString() { String prefix = getServerName() + '(' + getServerPoints() + ") serving " + getReceiverName() + '(' + getReceiverPoints() + "): "; return prefix + getScore(); } // mutators // -------- /** Records a point being scored by the server. It is assumed that, ** prior to the point being scored, the game was not over. */ public void pointForServer() { } // STUB!! /** Records a point being scored by the receiver. It is assumed that, ** prior to the point being scored, the game was not over. */ public void pointForReceiver() { } // STUB!! }