CSCI 161 - Lab 9: "Zipcodes Distance"

Objectives

The objectives of this assignment are to reinforce and help teach:

Overview

In this lab you will develop a program that asks the user to enter two 5-digit zip codes and then looks up latitude, longitude and state and city name information for each zip code by reading the zipcodes.txt text file supplied, calculates the approximate miles between the two zip codes using a method provided, and lastly, prints to the screen the distance between the two zip codes along with their city, state and zip code information.

The text file your program reads has one zip code entry per line. Each line has the following, in order:

  1. zip code (5 digits which should be read as a word and stored as a String)
  2. latitude (double)
  3. longitude (double)
  4. state-city (the remaining words of the line)
Following is an example
        
08889 40.6 -74.76 NJ-WHITEHOUSE STATION
07095 40.55 -74.28 NJ-WOODBRIDGE
07481 40.99 -74.16 NJ-WYCKOFF        
        
        

Please see the "Output Specification" for below for details on how your program should prompt the user for input and then present the information read from the file, calculated and in some case reformated.

Instructions

Following are the instructions and you should follow them carefully:

  1. Using Eclipse create a new Java Project and name it: Lab9
  2. As with all your labs, add a class of the same name, Lab9, and include in that class a main method.
  3. Your program should be properly commented, indented and use whitespace appropriately.
  4. Your program should use several methods to reduce the code complexity and reduce the length of the main method. Your program should employ the following methods exactly (note return and parameters):
  5. Your program also needs a method called calculateDistance. The Case Study at the end of Chapter 6 includes a constant and the calculateDistance method you will need. The constant and method code are here for your ease of integration. The method should be used "as-is" without any modification. It is in your best interest to review and understand said case study.
  6. Your program will have to read the zipcodes.txt file. That file may be copied to your current working directory when on the Linux system through the following command:
                
    cp /home/grader/rogers161/Public/zipcodes.txt .
                
    A small snippet of the text file is here. The full file contains almost 42,000 zip code lines. Please watch this quick video guide for instructions on downloading the zipcodes.txt file to your laptop and adding it to your Eclipse project by clicking here.
  7. Your program must read the zipcodes.txt file once to figure out the number of lines (via the numLines method), then again to read all the contents of the file into four (4) arrays (via the readFile method) with each array sized to the number of lines in the file. Said arrays are of type String, double, double and String for holding the zipcode, latitude, longitude and city name, respectively.
  8. Your program must deal with user input error and ask the user to enter a 5 digit zip code repeatedly until one is entered correctly (that is what the getZipCode method is for and you only have ONE version of that method, not two). The same is true for the findZipCode method; there is only one and it is called twice to find the indexes of the two different zipcodes.
  9. Your program should read the file only once, load the arrays when it reads the file, and not read the file a second time and instead us array access for finding zip codes, etc from that point on.
  10. Make sure to declare only one Scanner object for reading the user input and declare it in the main method (pass to other methods as needed).
  11. Your program should output *exactly* according to the "Output Specification" below. Not the special formatting of the City, State, Zipcode (in that order) when displayed.
  12. HELPFUL: Your program should employ a main method that adheres to the flowchart found here. Note the references to operations performed by methods as denoted by the italicized angle brackets (e.g. <<readFile>>)
  13. As a last resort, if you are confused by the instructions above and the flowchart for the main, you can start with a template for your Lab9 solution as found here.
  14. Your program must work with redirected input as well as input from the user. Test both.
  15. IMPORTANT: Your program will be graded according to the following rubric.
  16. When the lab is complete and working submit your Lab9.java file via AutoLab.

Output Specification

Following is the desired output format:

        
        
Please enter first zipcode:  17551
Please enter second zipcode:  90210
MILLERSVILLE, PA 17551 is 2331.91 miles from BEVERLY HILLS, CA 90210        
        
        
    

Deadline

This lab be submitted to the instructor by 11:59pm on Monday, November 20th.