Bryn Mawr College
CMSC 206: Data Structures
Fall 2015
Instructor: David Cooper
Assignment#1
Due on Tuesday, Sept 8
Title: Procesing Recall/refresher: Plotting US Postal Zip Code Locations
Purpose: The goal of this assignment is to help you remind yourself of the concepts that are required as pre-requisites for this course. Specifically, this assignment will require you to write a program in the Processing language. You will need to know how to define a class (data and methods), the use of arrays, strings and string operations, file input, dealing with data (and mapping values), and plotting simple points. This knowledge is required to continue further in this course. The rest of the course will build on your knowledge of these onwards on to the Java programming language. The data set chosen is simple, yet rich enough to result in an interesting plot (as you will see when you finish the assignment). Future assignments will process the data in many other ways.
Data File: zips.txt
Description: Write a Processing program to read in the data about all the postal zip codes in the 48 contiguous states of the United States. This data is over ten years old but will suffice for our purposes. 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. After reading the data your program should plot the geo-location of each zip code on a 2-dimensional screen. In order to be able to do this, you will need the x- and y- coordinates of each zip code. The data file contains the x- and y- values computed from each zip code's latitude and longitude locations. However, the coordinates are based on a different scale than your sketch proportions. 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
These values and the ones below are to be input from your program. 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 is to be plotted at the point <0.3135056, 0.7633538> and belongs to the town of Portsmouth, NH.
What to do:
1. Create a class called Place to model each zip code to contain the following data fields:
zip code, town, state, x and y coordinate
In addition to the constructor, define a draw() method that plots the zip code in the sketch window.
2. In your main sketch, set up the sketch window (you may make it so it occupies the entire display using displayWidth and displayHeight variables). Input the data from the provided data file and store it an an array of Place objects. Next, plot all the zip codes in the sketch in black against a white background.
3. Once done, modify the program to plot all the zip codes in the state of Pennsylvania in a red color.
What to Hand-in:
1. Hand in a printout of your program code along with a screen shot of the final sketch window.
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.
Grading: This assignment will be graded based on the CS110 Grading Policy.
Thanks: This assignment is based upon the data provided by Ben Fry (Visualizing Data, O'Reilly 2008). Thanks, Ben!