CS 151 - Introduction to Data Structures
Homework 3
Lists - Zipcode lookup
Read the program design principles and code formatting
standards carefully. You are expected to adhere to all stated standards.
Overview
This project uses the List151Impl class and object-oriented design with inheritance. The general idea is that you are
given file containing data about zip codes. Each line of the file contains data about exactly one zip code. However,
some of the data is missing on some of the lines. The goal is to create classes that store exactly the available
information about each zip code, and no more. So, you will create classes with inheritance that allow you to store
all the data available in the minimum possible space. All of the data must be stored in a single instance of a class that implements List151 (in other words List151Impl). You will
then query this container to deliver information about zip codes.
Code is available by scp at
/var/www/html/cs151/Data/Hw3/List151.java
/var/www/html/cs151/Data/Hw3/List151Impl.java
/var/www/html/cs151/Data/Hw3/BagOfStuff.java
Use scp to get the code. For example:
scp YOURUNIXLOGIN@web2.cs.brynmawr.edu:/var/www/html/cs151/Data/Hw3/BagOfStuff.java BagOfStuff.java
or from the web at (for example):
https://cs.brynmawr.edu/cs151/Data/Hw3/List151.java
https://cs.brynmawr.edu/cs151/Data/Hw3/BagOfStuff.java
https://cs.brynmawr.edu/cs151/Data/Hw3/List151Impl.java
You will need to use scp to get files from this location regardless of whether you are on your personal laptop or one of the department computers.
Data
shuffzips.csv
The data for this assignment is available at
/var/www/html/cs151/Data/Hw3/shuffzips.csv. As above this file is available through your browser or scp.
The lines in this file contain 12
comma-separated fields that look like the three lines below.
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,,,
10029,STANDARD,NEW YORK,NY,PRIMARY,40.71,-73.99,NA-US-NY-NEW YORK,false,31490,48403,1050141146
There is no header line. Initialize your instance of List151Impl so it can hold at least 50000 entries.
The fields in each row are:
- zip code
- type -- ignored
- city name
- state abbreviation
- type 2 -- ignored
- Latitude
- Longitude
- long code -- ignored
- true or false -- ignored
- population 1
- population 2
- another number -- ignored
For this assignment we care about only: zip code, city name, state, latitude, longitude and
population 2. Some lines are missing the longitude and latitude and population (the second sample line above), some are
missing population but have longitude and latitude (the first sample line above). All lines have
the correct number of commas (11). There are no lines for which the longitude and latitude are not known but
the population is known.
Given this description, the data falls into 3 groups:
- those for which location and population are known
- those for which only location is known
- those for which neither location nor population is known.
Your
first task is to design a set of java classes so that each of these groups can be stored in an instance that
is capable of storing the available information, and no more. These java classes MUST be linked to each
other using inheritance. For instance, if you define a class Place that stores group 3 data, then you might
make a class
public class LocatedPlace extends Place
to store group 2 data and another class for a place for which the population is also known.
Requirements
- You must store data in classes you create. These classes should hold exactly as much information as is
contained in a row of the data file. If the row is missing a data item, then you should use a class
that does not have space for the missing item. You may use the class design suggested above for your
classes.
- You MUST use inheritance in your class design.
- The only Data Structure you should use in this assignment is one that extends List151. You may use only one instance of this class.
- You may read the contents of shuffzips.csv at most once.
- Not a requirementUse ReadCSV.java (from lab1 and homework1) to read the data file. Your life will be better. You may extend or change ReadCSV however you see fit.
- When searching for a data item in List151Impl you must use the getInstance method. Do not write your
own search. Rather, appropriately override the equals method of your classes so that getInstance works. That is, write an equals
method that determines if two items are equal by comparing ONLY their zip codes. (Hint, to use getInstance you will need to pass in an instance of the Place class. So, after getting a zip code to look for from the user, create an instance of Place using only that zip code, then pass that instance into the getInstance method.)
- After reading in the data, your program should support user interaction similar to the following:
Enter a zip code to lookup (q to quit): 19380
West Chester,PA 19380 Pop:43281 Lat:39.95 Lon:-75.60
Enter a zip code to lookup (00000 to quit): 07040
Maplewood,NJ 07040 Pop:20973 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): q
Goodbye
That is, the output should show all of the information known about a given zip code. The output should not show that nulls or some other ugliness for information that is not known.
- 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 public
instance variables
- Statics. Do not use any static variables or static methods other than Main methods of classes.
- Scanner. Use the java Scanner class for user interaction only.
The directions are slightly changed from homework 1
Your submission will be handed in using the submit script.
If you write your program on computers other than those in the lab, be aware that your program will be graded based on how it runs on the
department’s Linux server, not how it runs on your computer. If you are using Java 11, you will not have any problems with Java compatability. A way you might get into trouble is, for instance, if you developed this program on your personal computer and made a local copy of the uszipcodes.csv file and hardcoded the address of that file on your computer into your program.
Make a README
Once you have finished coding (and fully commenting your code) make a README file. This file should follow the format of this sample README. This is your opportunity to tell me what went well or poorly, what is still broken and why, etc. I will read, and often respond to, everything you write in the README.
The easiest place to write your readme is within VSC. Make a file just like a standard java file but name it README.txt then just write in it. You should start by copying the sample readme.
Submit
If you developed this program on your own computer, do the following to transfer your program to the Linux computers so you will be able to submit.
- Open a terminal window on your computer (a windows powershell or a Mac terminal)
- Connect to a the CS file server
ssh YOURUNIXNAME@goldengate.cs.brynmawr.edu
Enter your Unix password when prompted
- On the linux computer:
cd CS151
mkdir a3
You made the CS151 directory in Lab 1 . You can change a3 to whatever you like, the directions below assume a3.
- Leave this terminal window open and connected to Linux, you will use it again in a couple of steps
- Within VSC open for your homework 3 project ... open a terminal by going to the Terminal menu and selecting "new terminal"
- In the Terminal inside of VSC (usually the lower right third of the screen) you should be in the directory containing your program. Enter
scp * YOURNAME@goldengate.cs.brynmawr.edu:cs151/a3
- You should get messages on screen showing that each file in this directory has been copied.
- Confirm that the copy was successful. Back in the Terminal you opened on the Linux machines (in step 2)
ls a3
This should show a list of of the files you just copied in your scp command.
- When all of the files are in the a3 directory and you are still in the CS151 directory
/home/gtowell/bin/submit -c 151 -p 3 -d a3
This says to submit for project 3 (-p) everything in the directory a3 (-d) for the class 151 (-c). You should see listing of all the files you submitted and a message that says "success".
- You can submit multiple times. I will grade only the last submission -- unless you tell me otherwise. The submission process attaches a timestamp so I know when you submitted (down to the second). The closest submission I have ever received to the deadline is 7 seconds.
Approximate Grading
Grades for this assignment will be assigned according the to the following rough percentages
- 40% -- Program follows requirements above
- 20% -- Program compiles and runs
- 20% -- program follows style and design guidelines
- 10% -- Readme
- 10% -- Other