Importantly, your program should only read the zip code file once!
After reading and storing all of the zip codes, your program should continuously prompt the user for a zipcode until the user enters '00000' to quit.
Here is a sample session:
zipcode: 19010 Bryn Mawr, PA zipcode: 99400 No such zipcode zipcode: 91729 Rancho Cucamonga, CA zipcode: 00000 Good Bye!In this session everything is from the program other than the 5 digits immediately following "zipcode:"
The first line is a special line, giving some basic info about the file, in the following comma-separated values:
where the first field in the line is an integer giving you the number of
zip codes stored
in the file. The rest of the line contains column headers for the file. Other than the number of zip codes,
this line can be ignored.
The rest of the lines come in the following format:
where the comma-separated fields have the following meanings:
zip | the 5-digit zipcode |
town name | name of the town with the zipcode |
state code | 2-character encoding of the state name |
population | population in this zipcode, an integer |
males | number of males in this zipcode, an integer |
females | number of females in this zipcode, an integer |
Sample snippet:
There are 42,613 entries following the first line. Zipcode 00501 belongs to the town of Holtsville, NY, for which we have no population recorded. Importantly, do NOT hard code 42,613 into your program. Rather read the first line, extract the number of lines; then create the appropriately sized array.
In this assignment, you will ignore the population numbers, and store only the zip code, the town and the state. Note however that there are towns whose names have more than one word, such as “Palm Springs”.
scp YOURNAME@165.106.10.186:/home/gtowell/Public/206/a2/testZip.csv . scp YOURNAME@165.106.10.186:/home/gtowell/Public/206/a2/uszipcodes.csv .This should copy two files to your machine, testZip.csv ands uszipcodes.csv. (Recall that the period at the endof the line is significant, do not miss it.)
/** * Creates a place with zip, town name and state * @param zip a 5 digit zip code * @param town the town name * @param state the state abbreviation */ public Place(String zip, String town, String state);There are many other ways you might implement the Place constructor. Do it this way in this assignment.
/** * Reads a zip code file, parsing and storing every line * @param fileName the zip code file * @throws FileNotFoundException if the file does not exist */ public void readZipCodes(String fileName) throws FileNotFoundException /** * Find a Place record given a zip code * @param zipCode the zip code to find. * @return the place, or null if the zip code is unknown */ public Place lookupZip(String zipCode)Implement the class Places and the above methods.
Place[] allZips;which will get initialized and filled by readZipCodes. Then the method lookupZip will scan that array to find information.
A smaller file (of the same format), named testZip.csv, is available as well, in case you want to debug on a smaller dataset.
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 per my installation instructions in lab 2, 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. To fix, be sure to change the file name to /home/gtowell/Public/206/a2/uszipcodes.csv before handing your program in.The submission should include the following items:
The following steps for submission assume you are using Visual Studio Code, and that you created a folder named Assignment2 in the directory /home/YOU/cs206/