Assignment 5

As part of an applications programming team for the Buyalot Mall, you have been given the task of completing the MallSearch program, which information desk staff will use to search for appropriate stores, at the request of mall patrons. The program asks first for the search type ("exact" or "wild" — short for "wildcard"), then the store type (e.g., "entertainment"), the store name (e.g., "Joe's Records") and finally an item which the store sells (e.g., "CD"), after which it prints all store records which match. If nothing is entered for a criterion (i.e., a blank line is typed), then the criterion defaults to a wildcard, i.e., any will do. If "exit" is given for the search type, the program terminates. The following sample dialogue illustrates this (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 CDs, located on floor 1, #11.
"HMV": entertainment store selling CDs, located on floor 3, #1.
2 matches printed.
Please enter match type ('exact' or 'wild') or 'exit': exit

%

Existing classes

Some work has already been done: Your brilliant colleague "Mad Jack" Jackson wrote two classes, MallMap and Store, and most of a third, MallSearch, before disappearing, leaving only the class files and their documentation! You must complete the work on the MallSearch class, using Jack's classes as appropriate.

The MallMap class builds an index of all the stores in the mall, using instances of Store. It is documented here, and the class file for it can be downloaded here.

The Store class represents a single store, recording the store name, type, and the types of things it sells. It is documented here, and the class file for it can be downloaded here.

The MallSearch class is the application class. Its main method reads in the criteria described above and invokes the method printSearchResults to perform the actual search. It is this method which you must now complete. Unfortunately, the arguments have not been specified for the method, so you will also have to decide which arguments you think you need to pass in to the method, both formal and actual. In addition to these two methods, three service methods have been defined: getLineWithPrompt, getMatchType, and getStoreType, as well as three useful constants: MATCH_EXACT, MATCH_WILDCARD, and EXIT. You can use any or all of these, or none, as seems appropriate. You can also define your own constants or service methods, if you think it appropriate. (Remember that reuse is generally a good thing, and your use of existing code will be considered when marking the assignment.) It is documented here, and the Java source for it can be downloaded here.

When you compile and run your code, you must make sure the class files downloaded from this site are in the same directory as your MallSearch code!

Your Job

  1. Download the class and Java files mentioned above, and print out and read the documentation on them.
  2. Decide what information you will need in the printSearchResults method to perform the search, and make appropriate changes to the invocation in main and the method declaration.
  3. Implement printSearchResults so that MallSearch satifies the requirements listed below.
  4. Document your code, using normal comments (don't bother trying to write Javadoc documentation). Don't forget to document any and all service routines you might write, also.
  5. Test your implementation thoroughly.
  6. Submit your version of MallSearch.java, using the same mechanism as used for the previous four assignments.
Note that only MallSearch.java should be editted. To help you focus on important parts, the places needing change are marked with three asterisks ("***") in comments in that file.

MallSearch Requirements

The MallSearch class (and implicitly, your implementation of printSearchResults) must satisfy the following requirements: To help you verify that your implementation works, here is a more complete log:
% java MallSearch
Please enter match type ('exact' or 'wild') or 'exit': exact
Please input the store type: book
Please input the store name:  
Please input an item type:  
Sorry, no matches found.
Please enter match type ('exact' or 'wild') or 'exit': wild
Please input the store type: book
Please input the store name:  
Please input an item type:  
"The Bookworm": book store selling books, located on floor 1, #5.
"Kohl's": book store selling books, located on floor 3, #2.
2 matches printed.
Please enter match type ('exact' or 'wild') or 'exit': wobble
Unknown match type. Using wildcard.
Please input the store type:  
Please input the store name: orium
Please input an item type:  
"The Emporium": gift store selling ceramics, located on floor 1, #3.
"The Wombatorium": specialty store selling stuffed wombats, located on floor 3, #3.
2 matches 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: art
"The Hollow Tree": gift store selling art, located on floor 2, #8.
1 match printed.
Please enter match type ('exact' or 'wild') or 'exit': WILD
Please input the store type: department
Please input the store name: HUDSON
Please input an item type: cloth
"Hudson's Bay Company": department store selling clothing, located on floor 1, #1.
1 match printed.
Please enter match type ('exact' or 'wild') or 'exit': wild
Please input the store type: entertainment
Please input the store name:  
Please input an item type:  
"Sam's": entertainment store selling CDs, located on floor 1, #11.
"HMV": entertainment store selling CDs, located on floor 3, #1.
"Ars Electronica": entertainment store selling guitars, located on floor 3, #7.
3 matches printed.
Please enter match type ('exact' or 'wild') or 'exit': wild
Please input the store type:  
Please input the store name:  
Please input an item type:  
"Hudson's Bay Company": department store selling bedding, located on floor 1, #1.
"Meerschaum Mania": specialty store selling pipes, located on floor 1, #2.
"The Emporium": gift store selling ceramics, located on floor 1, #3.
"The Bookworm": book store selling books, located on floor 1, #5.
"Glad rags": clothing store selling dresses, located on floor 1, #6.
"Ruggles": home store selling carpets, located on floor 1, #7.
"East 52nd": clothing store selling pants, located on floor 1, #9.
"The Bermuda Triangle": clothing store selling sunglasses, located on floor 1, #10.
"Sam's": entertainment store selling CDs, located on floor 1, #11.
"Pickle Heaven": food store selling food, located on floor 2, #1.
"Squishy's Squids": food store selling frozen squid, located on floor 2, #2.
"C-C-C-Cupcakes": food store selling cupcakes, located on floor 2, #4.
"The Skinned Weasel": food store selling pub, located on floor 2, #5.
"Dirt City": specialty store selling vacuum cleaners, located on floor 2, #7.
"The Hollow Tree": gift store selling sculptures, located on floor 2, #8.
"Sears": department store selling bedding, located on floor 2, #9.
"HMV": entertainment store selling CDs, located on floor 3, #1.
"Kohl's": book store selling books, located on floor 3, #2.
"The Wombatorium": specialty store selling stuffed wombats, located on floor 3, #3.
"Le Clochard": clothing store selling suits, located on floor 3, #4.
"Millicent's Millinery": clothing store selling hats, located on floor 3, #5.
"Homer's": home store selling pots, located on floor 3, #6.
"Ars Electronica": entertainment store selling guitars, located on floor 3, #7.
23 matches printed.
Please enter match type ('exact' or 'wild') or 'exit': exit

%
You can test your application automatically by redirecting this file of input lines (derived from the above) and comparing your program's output against this output file.  Note: if you run the supplied program without modification, you will get this output instead.