import java.io.PrintWriter; import java.io.BufferedReader; import java.io.InputStreamReader; /** * Some experiments to better understand looped queues. */ public class TestLoopedQueue { public static void main(String[] args) throws Exception { // Prepare input and screenput. BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in)); PrintWriter screen = new PrintWriter(System.out, true); LoopedQueue lq = new LoopedQueue(); boolean done = false; while (!done) { screen.print("Command: "); screen.flush(); String command = keyboard.readLine(); if (command.equals("quit")) { done = true; } else if (command.equals("help") || command.equals("?")) { screen.println("add - add an element"); screen.println("get - get an element"); screen.println("dump - print the queue"); screen.println("quit - quit already"); } else if (command.equals("add")) { screen.print("Enter a string to add: "); screen.flush(); String addMe = keyboard.readLine(); lq.add(addMe); } else if (command.equals("get")) { screen.println(lq.get()); } else if (command.equals("dump")) { lq.dump(); } else { screen.println("Sorry, I didn't understand '" + command + "'"); } } // while // That's it, we're done. System.exit(0); } // main(String[]) } // class TestLoopedQueue