Bryn Mawr College
CMSC 206: Data Structures
Spring 2014
Instructor: Deepak Kumar

Assignment#3

Due on Thursday, February 13

Title: Searching US Postal Zip Code Locations

Purpose: Write a complete working Java program to repeatedly input a zip code from the user. In response, your program will output the name of the town and the state to which it belongs. In case the zip code doesn't exist, it tells the user about it (see xample interaction below). You will use the same zip code data as in the first assignment:

Data File: zips.txt

Description: The data file provided (see link above) contains over 41,000 US Postal Zip Codes and the names of the town and state they belong to. Here are the details of the data file's format:

The first line of the data file is a bunch of comma-separated values in the format shown below:

#NUM_ZIPCODES,MIN_X,MAX_X,MIN_Y,MAX_Y

These indicate the following:

NUM_ZIPCODES is the total number of zip codes present
MIN_X and MAX_X are the minumum and maximum values of the mapped x- coordinates of all the zip codes
MIN_Y and MAX_Y are the minumum and maximum values of the mapped x- coordinates of all the zip codes

The rest of the data file contains entries (one line for each zip code) in the following format:

ZIP_CODE    X_COORD     Y_COORD     TOWN_NAME, STATE

ZIP_CODE is the 5 digit zip code
X_COORD is the X coordinate of the zip code in the grid defined by MIN_X and MAX_X
Y_COORD is the Y coordinate of the zip code in the grid defined by MIN_Y and MAX_Y
TOWN_NAME, STATE is the name of the town and the 2-letter state abbreviation.
These 'four' values are separated by a TAB character (i.e. it is a TAB-separated file).

Example entries:  
00210    0.3135056    0.7633538    Portsmouth, NH
00211    0.3135056    0.7633538    Portsmouth, NH
00212    0.3135056    0.7633538    Portsmouth, NH 

The first line is for the zip code 00210 which could be plotted at the point <0.3135056, 0.7633538> and belongs to the town of Portsmouth, NH.

In this assignment, you will ignore the corrdinates, and store only the zip code, the town and the state.

What to do:

Create a class called Place to model each zip code to contain the following data fields:

zip code, town, state

Additionally, you will need to define the needed accessor, and modifier methods. Also, define the print method toString() and a comparison method equals() to compare a given zip code against a place object.

Input the data from the provided data file and store it an an array of Place[] objects. Use the Java dialog commands you have learned to do user interaction. Simultaneously, print out all user interactions in the Console Window. For example:

You asked me to search for zip code: 19010
The zip code 19010 belongs to Bryn Mawr, PA
Do you want me to search again? Yes

You asked me tyo search for zip code: 99400
The zip code 99400 does not exist.
Do you want me to search again? Yes

You asked me tyo search for zip code: 91729
The zip code 91729 belongs to Rancho Cucamonga, CA
Do you want me to search again? No

Good Bye!

What to Hand-in:

1. Once done, hand in a printout of your program code along with a screen shot of the Console window showing an interaction with at least a total of five searches (both successful and unsuccessful).
2. Write a short reflection on your experiences with this assignment.
3. Staple all of these together and hand them in at the start if the class on the due date.

Thanks: This assignment is based upon the data provided by Ben Fry (Visualizing Data, O'Reilly 2008). Thanks, Ben!

Back to CMSC206 Course web page.