CMSC 206: Data Structures
Due on Tuesday, October 4, 2016
In this exercise, we will essentially do something similar to your Assignment#1 but embellish in two ways:
Query: Cambridge, MA Found... Town: Cambridge, MA, 02138 Population: 36314 (19240 Female, 17074 Male)
[Hint: You will need to modify the equals() method in the place class.]
Also, change your program so that all input and output in this program will be from the Console Window (see page 658 of your text). A user may misspell the name of a town or enter the name of a town that does not exist (i.e. not contained in your database). In that case, just print out a message to that effect and continue to query for the next town. You should be careful about the case-sensitivity of the town/state names. One way to avoid any problems is to convert the strings being compared to all upper or lower case.
Note that you are only searching for the first occurrence of the town querried. Depending upon the size of the town, it may have several zip codes and hence several entries (e.g. Cambridge, MA). Extra Credit for a suggestion to implement when there are multiple zip codes in a town (this is optional and do not attempt this until AFTER you have completed the assignment).
For demonstrating the correctness of your program, test your program for the follwoing inputs:
Once you have completed the program, extend it to count the number of comparisons needed to answer a query. Then, for the input data above, compute and output the following:
To show your output (only the latest version of your program is sufficient) cut and paste the contents of the Console Window in a text/Word file and print it. Additionally, hand in a prinout of the complete Java program.
Work on your program one piece at a time. And then add the statements to count the number of comparisions.
What to Hand-in:
Many towns have several zip codes. For example, Cambridge, MA has five zip codes, Buffalo, NY has over 40 zipcodes. Each zipcode may have its population data. Extend the program to aggregate the population data for each zipcode in a town when printing results. Do this for these towns: Cambridge, MA; Buffalo, NY; Cut and Shoot, TX; Cool, CA; and New York, NY.Query: Cambridge, MA Found...
Back to CS206 Course Materials