ArrayList and Inheritance - Zipcodes with
populations and locations
CS 206 - Introduction to Data Structures
Assignment 3 - due Friday Sept 27 prior to 11:59PM
Read, and follow, program design principles (http://cs.brynmawr.edu/cs206/design.pdf) and code formatting standards (http://cs.brynmawr.edu/cs206/style.html) carefully. You are expected to adhere to all stated standards.
In this project, we will again use ArrayList and work with object-oriented design and inheritance.
You may find it convenient to build on top of Assignment 2. Some of the instructions below assume that you are doing so.
This assignment uses the data file /home/gtowell/Public206/data/a3/ziplocs.csv which gives information about zipcodes and their associated latitudes and
longitudes (as decimal numbers), among other things. This week the task is to organize the data into classes stored in
an ArrayList that allows us lookups similar to those in Assignment
2.
Input File Format
The file ziplocs.csv contain 12
comma-separated fields that look like this:
"07677","STANDARD","WOODCLIFF-LAKE","NJ","PRIMARY",41.02,-74.05,"NA-US-NJ-WOODCLIFF LAKE","false",2945,5471,325436960
The fileds are:
- Zipcode
- ZipCodeType
- City
- State
- LocationType
- Latitude
- Longitude
- Location
- Decommisioned
- Tax Returns Filed
- Estimated Population
- TotalWages
We will only use seven of these fields: the zipcode, city, state, latitude, longitude, tax returns filed and estimated population. As in the last assignment, some lines are missing some information, but all lines have the correct number of commas (11). Unlike the previous assignment, this file does not contain a header row.
We can place all
zipcodes this this file into one of three categories: zipcodes with population info (tax returns and estimated population) and location, zipcodes with a location only, and zip codes without either. (The
dataset does not contain any zipcodes with a population but no location.)
We’ll call the first a PopulatedPlace, the second a LocatedPlace, and the
third just a Place. These types naturally form an inheritance hierarchy, where
PopulatedPlace is a subclass of LocatedPlace (every PopulatedPlace is also a
LocatedPlace) and LocatedPlace is a subclass of Place (every LocatedPlace is also a
Place).
2 Specific Tasks
- All classes should be public in this assignment.
- Data file is /home/gtowell/Public206/data/a3/ziplocs.csv. The data should be read directly from this file. Do not make and read from local copies. (More precisely, the version you submit must not use a local copy.)
- Override the toString method of your Place class to return an appropriate
string represenation. For example, the Place for Bryn Mawr should return
"Bryn Mawr, PA".
- Write a new class LocatedPlace that is a subclass of Place. Include
appropriate instance variables, constructor and getters.
- The LocatedPlace class must also have an overridden toString method
that includes the location information in the string returned. For example,
for Bryn Mawr it would return the string "Bryn Mawr, PA 40.02 -75.31".
- Write a new class PopulatedPlace that is a subclass of LocatedPlace.
Include appropriate instance variables, constructor and getters.
- The PopulatedPlace class must also override the toString method to
include the place’s household size in the string. You can estimate household size to be equal to (Estimated Population) / (Tax Returns Filed). For Bryn Mawr, this return. the string
"Bryn Mawr, PA 40.02 -75.31 Household size: 1.665".
(You can use the statndard java formatting of floating point numbers)
- Modify the readZipCodes method from LookupZip to read the new data file with the required data items. readZipCodes should construct the appropriate class (Place, LocatedPlace or Populated place) depending on the data line. That is construct a Place if there is no longitude/latitude, and a LocatedPlace is there is no population information.
Your program should read the file only once.
In this assignment you must store data in a single ArrayList not an array. Use the implementation of ArrayList in java.util.ArrayList, not the one on the class website.
- Update the main method to work with your new methods. Recall that the
appropriate toString() will be used when you print your three different
Place objects.
Here’s a sample session:
zipcode: 19010
Bryn Mawr, PA 40.02 -75.31 Household Size:1.665
zipcode: 99400
No such zipcode
zipcode:99781;
Ventie, AK 67.0 -146.37
zipcode: 00000
Good Bye!
3 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.
Your submission should have at least the following files:
- README: This file should follow the format of this sample README (https://cs.brynmawr.edu/cs206/README.txt)
- Source files:
The set of source files is likely to include at least the following:
Main.java, Place.java, LocatedPlace.java, PopulatedPlace.java, LookUpZip.java
- 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/
- Enter submit -c 206 -p 3 -d Assignment3
For more on using the submit script click here