Bryn Mawr College
CMSC 206: Data Structures
Fall 2016
Instructor: Deepak Kumar


Due on Thursday, September 22

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 example interaction below). The dataset of all the zip codes in the United States is available in the file:

Data File: uszipcodes.csv
Test Data File: testZip.csv

Description: The data file provided (uszipcodes) contains over 40,000 US Postal Zip Codes and the names of the town and state they belong to. Initially, you should use the much smaller (only 15 zip codes) data file (testZip.csv). 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:


These indicate the following:

NUM_ZIPCODES is the total number of zip codes present followed by the text field names: zip,city,state,population,males,females

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


ZIP_CODE is the 5 digit zip code
TOWN_NAME, STATE is the name of the town and the 2-letter state abbreviation.
POPULATION,#MALES,#FEMALES are the population, number of males, and number of females

Several entries have the POPULATION,#MALES,#FEMALES entries missing (i.e. they just appear as ",,,").

Example entries:  
56320,Cold Spring,MN,8080,4050,4030

The first line is for the zip code 56315 which belongs to the town of Branden, MN that has a population of 1591 of which 829 are males and 762 are females.

In this assignment, you will ignore the population numbers, 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 GUI 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 to search for zip code: 99400
The zip code 99400 does not exist.
Do you want me to search again? Yes

You asked me to 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.

Back to CMSC206 Course web page.