import java.io.PrintWriter; import java.io.BufferedReader; import java.io.InputStreamReader; /** * Some experiments to better understand binary search trees */ public class TestHashTable { 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); HashTable dict = new HashTable(); 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("drop - delete an element"); screen.println("dump - print the tree"); screen.println("quit - quit already"); } else if (command.equals("add")) { screen.print("Enter the key: "); screen.flush(); String key = keyboard.readLine(); screen.print("Enter the value: "); screen.flush(); String value= keyboard.readLine(); dict.add(key, value); } else if (command.equals("get")) { screen.print("Enter the key to get: "); screen.flush(); String key = keyboard.readLine(); screen.println(dict.get(key)); } else if (command.equals("drop") || command.equals("delete")) { screen.print("Enter the key to delete: "); screen.flush(); String key = keyboard.readLine(); dict.delete(key); } else if (command.equals("dump")) { // dict.dump(); } else { screen.println("Sorry, I didn't understand '" + command + "'"); } } // while // That's it, we're done. System.exit(0); } // main(String[]) } // class TestHashTable