import java.util.Scanner; /* Java application having as its purpose to be used in testing the class ** TennisGameState2. The user is asked to enter names for the server and ** receiver in a game of tennis, and then to enter s's and r's to identify ** which player ('s' for server, 'r' for receiver) scored each point in ** the game. Entering 'q' results in the program terminating. ** Characters other than 's', 'r', and 'q' are ignored, as are any ** characters that describe a point following the end of the game. ** ** Author: R. McCloskey ** Date: September 2026 */ public class TennisGameState2Tester { private static Scanner keyboard = new Scanner(System.in); public static void main(String[] args) { System.out.println("Welcome to the TennisGameState2Tester program.\n"); String serverName = getString("Enter name of server: "); String receiverName = getString("Enter name of receiver: "); System.out.println(); TennisGameState game = new TennisGameState2(serverName, receiverName); System.out.println(game.toString()); boolean quit = false; while (!game.isOver() && !quit) { System.out.print("\nEnter s or r (or a sequence thereof): "); String response = keyboard.nextLine(); for (int i=0; i != response.length() && !game.isOver() && !quit; i=i+1) { char ch = response.charAt(i); if (ch == 's') { game.pointForServer(); System.out.println(game.toString()); // display status of game } else if (ch == 'r') { game.pointForReceiver(); System.out.println(game.toString()); // display status of game } else if (ch == 'q') { quit = true; } else { System.out.println("Ignoring meaningless character '" + ch + "'"); } } } if (quit) { System.out.println("\nGame aborted."); } System.out.println("\nGoodbye."); } /* Displays the specified message (prompt) and returns the response ** entered by the user at the keyboard. */ private static String getString(String prompt) { System.out.print(prompt); return keyboard.nextLine(); } }