001 package ps6;
002
003 import java.io.*;
004 import java.util.*;
005 /**
006 * This class implements an interactive text-based interface for Husky Maps.
007 **/
008
009 public class TextUI {
010
011 public static void main(String args[]) {
012 try {
013 if (args.length == 0) {
014 printUsage();
015 return;
016 }
017
018 TextUI textui;
019
020 String databaseName = args[0];
021 List<String> zipcodes = new ArrayList<String>();
022 for (int i = 1; i<args.length; i++) {
023 zipcodes.add(args[i]);
024 }
025
026 textui = new TextUI(databaseName, zipcodes);
027
028
029 BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
030 textui.interactiveLoop(r, System.out);
031
032 } catch (IOException e) {
033 System.out.flush();
034 System.err.println(e.toString());
035 e.printStackTrace(System.err);
036
037 }
038 }
039
040 private static void printUsage() {
041 System.err.println("Usage:");
042 System.err.println("java ps6.TextUI directory-name zipcode1 zipcode2 ... zipcodeN");
043 }
044
045 private final String databaseName;
046 private final List<String> zipcodes;
047
048 /**
049 * @requires databaseName != null && zipcodes != null
050 *
051 * @effects Creates a new TextUI which loads from databaseName
052 * and limits its search to the zipcodes given, unless the list
053 * is empty or null, in which case it searches over all zipcodes.
054 **/
055 public TextUI(String databaseName, List<String> zipcodes) {
056 this.databaseName = databaseName;
057 this.zipcodes = new ArrayList<String>(zipcodes);
058 }
059
060 /**
061 * TODO:Spec to be written by student.
062 **/
063 public void interactiveLoop(BufferedReader input, PrintStream output)
064 throws IOException
065 {
066 //loop:
067 // read from input
068 // find directions
069 // write to output
070 }
071
072 }