CS 206 - Introduction to Data Structures
Homework 3
ArrayList - Zipcode lookup
Due October 1, prior to 11:59pm
Read the program design principles and code formatting
standards carefully. You are expected to adhere to all stated standards.
Overview
This project uses ArrayList (use java.util.ArrayList) and object-oriented design with inheritance. The general idea is that there are two data files, both of which contain information about US zip codes. You need to read that data into appropriately designed classes, store those classes in a single ArrayList then answer questions using the stored information. (More on that below.)
Data
There are two data files. Each is described in a section below.
ziplocs.csv
ziplocs.csv contains a header line at the top with column names. Thereafter, the lines contain 12
comma-separated fields that look like this:
"00705","STANDARD","AIBONITO","PR","PRIMARY",18.14,-66.26,"NA-US-PR-AIBONITO","false",,,
"09005","MILITARY","APO","AE","PRIMARY",,,"EU-DE-WEISBADEN AAF OMDC","false",,,
We will only use three of these fields,
- #1 -- the zip code
- #6 -- the latitude
- #7 -- the longitude
Some lines are missing the longitude and latitude (like the second sample line), but all lines have
the correct number of commas (11).
uszipcodes.csv
uszipcodes.csv also contains a header line. Thereafter, the lines contain 12
comma-separated fields that look like this:
49079,Paw Paw,MI,13606,6764,6842,
00636,Rosario,PR,,,,
From this file we will use 4 fields
- #1 -- the zip code
- #2 -- the city name
- #3 -- the state name
- #4 -- the population
As above, some lines are missing population data, but all have the correct number of commas and all have zip, city name and state.
Requirements
- You must store data in classes you create. These classes should hold exactly as much information as is contained a row of the data files. So, for instance, you would need a class to that hold place name, state name and zip code. Then you would need another class to hold all of that information plus location.
- Use inheritance appropriately when defining your classes. For instance, if you call the first class (which has only name, state and zip) Place, the you might define the class that also has location as
public class LocatedPlace extends Place
You might then define the class that also has population as
public class PopulatedPlace extends LocatedPlace
- There are no places for which the population is known but for which the location is unknown. So this set of three classes covers all all of the data.
- You can use several instances of ArrayList for storing information temporarily. However, when your program is answering user questions, all of the data must be in a single ArrayList..
- You may NOT use the Map206 class discussed in lecture on Sep 22 or any class in the Java libraries that uses or extends Map. Just use ArrayList.
- You may read the contents of each file at most once.
- After reading in the data, your program should support user interaction similar to the following:
Enter a zip code to lookup (00000 to quit): 19380
West Chester,PA 19380 Pop:49534 Lat:39.95 Lon:-75.60
Enter a zip code to lookup (00000 to quit): 07040
Maplewood,NJ 07040 Pop:23876 Lat:40.73 Lon:-74.27
Enter a zip code to lookup (00000 to quit): 00614
Arecibo,PR 00614 Lat: 18.45 Lon:-66.73
Enter a zip code to lookup (00000 to quit): 09848
Apo,AE 09848
Enter a zip code to lookup (00000 to quit): 88888
Not Found
Enter a zip code to lookup (00000 to quit): 00000
Goodbye
- All printing of information about a place should be done from toString. So, for instance, in the above interaction all of the printout of search results (other than "not found") should be done with a single line which might look like
System.out.println(place);
- Encapsulation. All classes should expose only that which other classes need. There should be no sharing of instance variables.
- Statics. Do not use any static variables or static methods.
- Scanner. Use the java Scanner class for user interaction only. All files should be read using BufferedReader and parsed using the split method of the String class.
Electronic Submissions
Your program will be graded based on how it runs on the
department’s Linux server, not how it runs on your computer.
1. README:
The usual plain text file README
2. Source files:
3. Data files used: uszipcodes.csv, ziplocs.csv
DO NOT INCLUDE: Data files that are read from the class site.
The following steps for submission assume you are using Eclipse, and that you created a project named Assignment3 in the directory /home/YOU/cs206/
- Put the README file into the project directory (/home/YOU/cs206/Assignment3)
- Go to the directory /home/YOU/cs206/Assignment3/
- Enter submit -c 206 -p 3 -d Assignment3
For more on using the submit script click here