CMSC 206: Data Structures
Assignment#4
Due on Thursday, October 9, 2014
The file zipCodes.txt contains data about towns and counties in the United States. This is a different file from the previous assignments. Each line of the file contains the following information:
Zip Code,Town Name, State, Phone Area Code, Dummy, County, Time Zone, Dummy, Dummy, County Population
where the fields labelled, Dummy, is information we will not be using in this exercise. Shown below, is an example line from the file:
02138,Cambridge ,MA,617,0472130681980,Middlesex ,Eastern ,40 ,2.63 ,1367000
From the above you can see that the line contains information about Cambridge, MA. Its zip code is 02138, It is in Middlesex county whose population is 1367000. It is in the Eastern time zone and has the phone area code (617). In this data file, Cambridge, MA has seven Zip Codes in it and thus there are seven entries in the data file (one for each Zip Code) for Cambridge, MA.
Query: Cambridge, MA Found... Town: Cambridge, MA, 02138 (Area Code: 617, Time Zone: Eastern) County: Middlesex, population 1367000
All input and output in this program will be from the Console Window. 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. 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 printing out the first occurrence of the town querried. Depending upon the size of the town, it may have several zip codes (and hence entries).
For demonstrating the correctness of your program, include a printout that shows the output from following queries:
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 the average number of comparions needed to answer a query, the average number of comparisions needed to answer a successful query, the average number of comparisons needed to answer an unsuccessful query.
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 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.
Technical Hints:
1. The data on each line is separated by a comma (',').
2. You will also need to make use of the trim() funtion of the string module to remove trailing blank characters in a string.
What to Hand-in: