import java.util.Scanner; /* Java application having as its purpose to be used in testing the class ** TennisGameState. The program creates an instance of that class and ** prompts the user to enter a sequence of s's and r's, where 's' ** (respectively, 'r') indicates a point scored by the server (resp., receiver). ** For each such input, the program displays the score of the game. ** Characters other than 's' or 'r' are ignored, as are any ** characters that describe a point following the end of the game. ** ** Author: R. McCloskey ** Date: September 2026 */ public class TennisGameStateTester { private static Scanner keyboard = new Scanner(System.in); public static void main(String[] args) { System.out.println("Welcome to the TennisGameStateTester program.\n"); TennisGameState game = new TennisGameState(); System.out.println(game); 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(); } else if (ch == 'r') { game.pointForReceiver(); } else if (ch == 'q') { quit = true; } else { System.out.println("Ignoring meaningless character '" + ch + "'"); } System.out.println(game); // display status of game } } if (quit) { System.out.println("\nGame aborted"); } System.out.println("\nGoodbye."); } }