// family name : // given names : // student no. : // aml account id : // course : // section : import york.*; /** * MallSearch is a search application to find information about stores in a mall. * MallSearch takes no arguments and immediately starts a dialogue, like that shown below: * (user inputs are underlined): * *
 * % java MallSearch
 * Please enter match type ('exact' or 'wild') or 'exit': exact
 * Please input the store type: department
 * Please input the store name: Hudson's Bay Company
 * Please input an item type: bedding
 * "Hudson's Bay Company": department store selling bedding, located on floor 1, #1.
 * 1 match printed.
 * Please enter match type ('exact' or 'wild') or 'exit':  
 * Please input the store type:  
 * Please input the store name:  
 * Please input an item type: CD
 * "Sam's": entertainment store selling CD, located on floor 1, #11.
 * "HMV": entertainment store selling CD, located on floor 3, #1.
 * 2 matches printed.
 * Please enter match type ('exact' or 'wild') or 'exit': exit
 * 
 * %
 * 
* * Two types of searches are permitted: "exact" and "wild" (short for * wildcard); "exit" can also be entered, which will cause the program to quit. *
* Permitted store types include all those accepted by * Store.typeNameIndex, * as well as the empty string. *
* There are no restrictions on store names or items. */ public class MallSearch { /** * Indicates the match of search string to name and/or item must be exact. */ private static final int MATCH_EXACT = 0; /** * Indicates the search string can match anywhere in the name and/or item. */ private static final int MATCH_WILDCARD = 1; /** * Indicates the command to quit. */ private static final int EXIT = -1; // *** HERE YOU MUST ENTER THE CORRECT DOCUMENTATION!! *** private static void printSearchResults ( /* *** HERE YOU MUST SPECIFY THE ARGUMENTS YOU THINK YOU NEED! *** */ ) { /* *** HERE YOU MUST IMPLEMENT THE METHOD *** */ York.println(); York.println("search method not yet implemented"); York.println(); } /** * Returns the text of the next input line, after printing the appropriate prompt. * @param prompt the text to print * @return the text of the input line typed in response to the prompt */ private static String getLineWithPrompt (String prompt) { York.println (prompt); return York.readLine (); } /** * Returns match type requested by the user, one of MATCH_EXACT, * MATCH_WILDCARD, or EXIT. The user is first prompted and their response is * matched against "exact", etc. If no match is found, the type defaults to * MATCH_WILDCARD. * @return the match type requested by the user or MATCH_WILDCARD, if no valid * type was requested */ private static int getMatchType () { String matchType = getLineWithPrompt ("Please enter match type ('exact' or 'wild') or 'exit': "); if (matchType.equalsIgnoreCase("exit")) return EXIT; else if (matchType.equalsIgnoreCase("exact")) return MATCH_EXACT; else if (matchType.equals("") || matchType.equalsIgnoreCase("wild")) return MATCH_WILDCARD; else { York.println("Unknown match type. Using wildcard."); return MATCH_WILDCARD; } } /** * Returns the type of store requested by the user. The user is repeatedly * prompted, until an acceptable type is entered. Permitted store types * include all those accepted by * Store.typeNameIndex, * as well as the empty string. * @return the type of store requested by the user */ private static int getStoreType () { // get store type, making sure it is valid int storeType = 0; String storeTypePrompt = "Please input the store type: "; do { String storeTypeName = getLineWithPrompt (storeTypePrompt); if (storeTypeName.length() == 0) storeType = Store.ANY_STORE_TYPE; else storeType = Store.typeNameIndex(storeTypeName); storeTypePrompt = "Invalid type. Please reenter: "; } while(storeType == Store.INVALID_STORE_TYPE); return storeType; } /** * Runs the application. */ public static void main(String args[]) { MallMap theMap = new MallMap(); int matchType = getMatchType (); while (matchType != EXIT) { int storeType = getStoreType (); String storeName = getLineWithPrompt ("Please input the store name: "); String item = getLineWithPrompt ("Please input an item type: "); printSearchResults ( /* *** HERE YOU MUST PROVIDE THE ARGUMENTS YOU THINK YOU NEED! *** */ ); matchType = getMatchType (); } } }