import java.util.Scanner; /* QueueTester.java ** This Java application is for the purpose of testing a class that ** implements the Queue interface. ** ** Author: R. McCloskey ** Date: October 2025 */ public class QueueTester { private static boolean keepGoing; private static Scanner keyboard = new Scanner(System.in); public static void main(String[] args) { System.out.println("Welcome to the QueueViaLink1Circ Tester!"); // For our current purposes, the class to be tested is QueueViaLink1Circ. Queue queue = new QueueViaLink1Circ(); testQueue(queue); } public static void testQueue(Queue queue) { keepGoing = true; while (keepGoing) { String command; // Prompt user until a non-empty string is entered do { System.out.print("\n> "); command = keyboard.nextLine().trim(); } while (command.length() == 0); // Having received a non-empty command, try to perform it. try { performCommand(queue, command); } catch (Exception e) { e.printStackTrace(System.out); System.out.println("\n Something went wrong; try again"); } } System.out.println("Goodbye."); } private static final String QUIT = "q"; private static final String HELP = "h"; private static final String SIZE = "#"; private static final String FRONT = "f"; private static final String ENQUEUE = "e"; private static final String DEQUEUE = "d"; private static final String PRINT = "p"; /* Applies the command described by the second parameter to the queue ** given by the first. */ private static void performCommand(Queue queue, String command) { Scanner comScanner = new Scanner(command); String commandCode = comScanner.next().toLowerCase(); String insertWarning = "Need to specify a string to insert!"; if (commandCode.equals(QUIT)) { keepGoing = false; } else if (commandCode.equals(HELP)) { printHelp(); } else if (commandCode.equals(SIZE)) { System.out.printf("Size of queue is %s\n", queue.sizeOf()); } else if (commandCode.equals(FRONT)) { System.out.printf("Front item is %s\n", queue.frontOf()); } else if (commandCode.equals(ENQUEUE)) { // insert item at rear if (!comScanner.hasNext()) { System.out.println(insertWarning); } else { String item = comScanner.next(); System.out.printf("Inserting \"%s\" at rear...\n", item); queue.enqueue(item); printContents(queue); } } else if (commandCode.equals(DEQUEUE)) { // remove item at front System.out.println("Removing item at front..."); queue.dequeue(); printContents(queue); } else if (commandCode.equals(PRINT)) { printContents(queue); } else { System.out.println("Unrecognized command."); } } private static void printHelp() { System.out.println(QUIT + ": to quit"); System.out.println(HELP + ": for help"); System.out.println(SIZE + ": to print size of queue"); System.out.println(FRONT + ": to print item at front of queue"); System.out.println(ENQUEUE + " x: to enqueue x at rear"); System.out.println(DEQUEUE + ": dequeue (remove item from front)"); System.out.println(PRINT + ": to print contents of queue"); } private static void printContents(Queue d) { System.out.println("Contents of queue: " + d); } }