handout #18

CSE142—Computer Programming I

Programming Assignment #8

due: Tuesday, 11/26/13, 9 pm

This assignment will give you practice with being a client of one class and being the implementer of a second class.  The classes store location information for various places of interest.  The target application is something like Google Maps where a user can make requests such as asking for restaurants that are near a certain location.

This assignment should not take as long to complete as the other assignments, so it is worth 10 points instead of the usual 20.  Because it is due just before the Thanksgiving holiday and because we will have limited IPL coverage, we will consider the Monday after break (12/2) to be one day away from the Wednesday before break (11/27).  For example, if you turn it in on Monday by 9 pm, it will be considered 2 days late.

Part A: Location Data (2 points)

The code we are writing will be more interesting to use if we have a lot of data to work with.  Companies like Google have invested significant resources to identify places of interest and to record their name, their address, and their location along with some tags that are relevant for searching.  We don’t have the resources of a company like Google, but we have a lot of students.  So we will use a crowdsourcing approach by having each student provide information for at least 10 places of interest in the general Seattle area.  You can include any place that you think a UW student would be likely to go including, for example, restaurants near the airport.

For each location, we want the following information:

·         Name of the place of interest

·         Street address (or similar description) for the place (not a complete address, just enough information to find it if you were near that location)

·         One or more search tags for this place

·         The latitude of this place

·         The longitude of this place

For example, suppose you want to include the Jack in the Box near campus in our data file.  You know its name and address and can come up with some tags.  To find its latitude and longitude, you can go to this web page:


Or you can get the information directly from Google Maps by following the instructions here:


You can add whatever search tags you think are appropriate, but Google provides a list of standard tags that would be useful to apply to your entries:


You should put the information together on separate lines, as in:

Jack in the Box

4749 University Way

restaurant, fast food



You are to choose at least 10 locations and to come up with a similar 5-line entry for each location.  The locations should not be private residences and should not include offensive descriptions.  Put it all together in a file called places.txt.  That means your file will have at least 50 lines.  You can use any text editor you like or you can use jGRASP, but if you use an editor like Microsoft Word, be sure to save it as plain text.  You are allowed to include a blank line between entries to make it easier to distinguish them while editing.  This part of the assignment can be completed separately and has a hard deadline of 9 pm Tuesday, 11/26.  There will be a link to a catalyst drop box available from the assignments tab on the class web page.

Part B: GeoLocationClient.java (2 points)

In this part of the assignment you will write client code to manipulate some GeoLocation objects.  The GeoLocation class is being provided to you, so you don’t have to write it.  You will instead be writing code that constructs and manipulates three GeoLocation objects.

The popular TV series Breaking Bad made use of geographic location information.  The Walter White character buried millions of dollars at a particular location in the desert outside of Albuquerque, New Mexico.  He then bought a lottery ticket to help him remember that his stash was buried at a latitude of 34 degrees, 59 minutes, 20 seconds and a longitude of -106 degrees, 36 minutes, 52 seconds.  Your client program will compute the distance between Walter’s stash and the local FBI building and a local studio known as ABQ Studios (where Breaking Bad was filmed).  Walter’s stash was supposedly buried in the desert, but from this client program, you’ll see that the coordinates they gave on the TV show are really the coordinates of the studio.

Your program is required to produce the following output:

the stash is at latitude: 34.988889, longitude: -106.614444

ABQ studio is at latitude: 34.989978, longitude: -106.614357

FBI building is at latitude: 35.131281, longitude: -106.61263

distance in miles between:

    stash/studio = 0.07548768123801672

    stash/fbi    = 9.849836190409732

You should use the latitude and longitude values in this log to construct the three GeoLocation objects.  You should then print the three objects and call the distanceFrom method twice to get the desired output.  Please note that the latitude/longitude information in the first three lines of output has to be produced by calls on the toString method of the GeoLocation class and the values in the final two lines of output have to be produced by calls on the distanceFrom method of GeoLocation.

Part C: PlaceInformation.java (6 points)

For this part of the assignment, you will write a class called PlaceInformation that stores information about a place of interest.   It should have the following public methods:

public PlaceInformation(String name, String address, String tag,

                        double latitude, double longitude)

public String getName()

public String getAddress()

public String getTag()

public String toString()

public double distanceFrom(GeoLocation spot)

The various “get” methods simply return the values that were provided when the object was constructed.  The toString method should return the name followed by a comma and space followed by the address.  Although the constructor takes a latitude and longitude, you should store this information inside the object using a GeoLocation object.  Be sure to properly encapsulate your object with private fields.

This class is similar to the GeoLocation class, so you can use it as a model for how to write your own class.  The GeoLocation class will also provide a useful example of how to comment your class.  Each method should be commented and the class itself should have a general comment.

We are providing a client program called PlaceInformationClient.java that can be used to test your class.  We are also providing a more sophisticated client program called SearchNear.java that will use the data that students are providing, although that program is an optional extra that is just for fun.