CMSC 206: Data Structures
Assignment#4

Due on Tuesday, March 4, 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.

  1. Write a program that reads all the data and stores it in an ArrayList. After reading the data file, your program should print out the number of entries in the list. As in the previous assignments, in the Place class, include the information described above, ignoring the Dummy fields.
  2. Write a program that, given a town name and its state, searches the list for the name of the town (the first occurrence only) and state, and then prints out all the information it knows about it, in the following format:
   Query: Cambridge, MA
   Found...
   Town: Cambridge, MA, 02138 (Area Code: 617, Time Zone: Eastern)
   County: Middlesex, population 1367000

All input and output in thsi 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:

  1. Cambridge, MA
  2. Jim Thorpe , PA
  3. Your birth place (if in the US)
  4. Bryn Mawr, PA
  5. Boring, OR
  6. Hell, MI
  7. Walla Walla, WA
  8. Surprise, NY
  9. Joe, MT
  10. Romance, AR
  11. Mars, PA
  12. Nuttsville, VA
  13. Rough and Ready, PA
  14. Dynamite, WA
  15. Good Grief, ID

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:

  1. A complete printout of the latest version of your program(s)
  2. a prinout of your program showing the outputs from the queries above (as well as some failed queries) and the three counts.

Back to CS206 Course Materials