import java.util.*; import java.io.*; public class InteractiveDBTester { public static void main(String[] args) { // initialize database CustomerDatabase db = new CustomerDatabase(); // confirm only one command-line argument if (args.length != 1) { System.out.println("Please provide input file as command-line argument."); System.exit(1); } // checks whether file exists and is readable File f1 = args[0]; if (!f1.exists()) { System.out.println("Error: Cannot access input file."); System.exit(1); } if (!f1.canRead()) { System.out.println("Error: Cannot access input file."); System.exit(1); } // load data and construct customer database Scanner stdin = new Scanner(System.in); // for reading console input printOptions(); boolean done = false; while (!done) { System.out.print("Enter option ( dfhisqr ): "); String input = stdin.nextLine(); input = input.toLowerCase(); // convert input to lower case // only do something if the user enters at least one character if (input.length() > 0) { char choice = input.charAt(0); // strip off option character String remainder = ""; // used to hold the remainder of input if (input.length() > 1) { // trim off any leading or trailing spaces remainder = input.substring(1).trim(); } switch (choice) { case 'd': // discontinue product case if (!db.containsProduct(remainder)) { System.out.println("product not found"); } else { db.removeProduct(remainder); System.out.println("product discontinued"); } break; case 'f': // find customer and return wish list if (!db.containsCustomer(remainder)) { System.out.println("customer not found"); } else { List wishlist = db.getProducts(remainder); System.out.println(remainder); System.out.print(":"); Iterator iter = wishlist.iterator(); while(!iter.hasNext()) { System.out.print(iter.next()); System.out.print(","); } } break; case 'h': printOptions(); break; case 'i': // *** Add code to implement this option *** break; case 's': // *** Add code to implement this option *** break; case 'q': done = true; System.out.println("quit"); break; case 'r': // remove customer if (!db.containsCustomer(remainder)) { System.out.println("customer not found"); } else { db.removeCustomer(remainder); System.out.println("customer removed"); } break; default: // ignore any unknown commands break; } } } stdin.close(); } /** * Prints the list of command options along with a short description of * one. This method should not be modified. */ private static void printOptions() { System.out.println("d - discontinue the given "); System.out.println("f - find the given "); System.out.println("h - display this help menu"); System.out.println("i - display information about this customer database"); System.out.println("s - search for the given "); System.out.println("q - quit"); System.out.println("r - remove the given "); } }