hw6
Class Location

java.lang.Object
  |
  +--hw6.Location
All Implemented Interfaces:
java.lang.Cloneable

public class Location
extends java.lang.Object
implements java.lang.Cloneable

This class is a way for objects to keep track of where they are in a 2-dimensional latitude & longitude based coordinate system.


Constructor Summary
Location(double lat, double lon)
          Create a new Location object, given a latitude and longitude.
 
Method Summary
 java.lang.Object clone()
          Create a copy of this Location object.
 double distance(hw6.Location other)
          Calculate the distance between two locations.
static void main(java.lang.String[] arg)
          Test harness for this class.
 java.lang.String toString()
          Provide a String representation of our location.
 void update(double lat, double lon)
          Update the current location based on the values provided.
 void update(hw6.Location loc)
          Update the current location based on the Location object provided.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Location

public Location(double lat,
                double lon)
Create a new Location object, given a latitude and longitude.

Parameters:
lat - the latitude. This value must be from -90. to +90. and this constructor throws a RuntimeException if that is not true.
lon - the longitude. This value can range from -180. to +180. and this constructor throws a RuntimeException if that is not true.
Method Detail

distance

public double distance(hw6.Location other)
Calculate the distance between two locations. This method assumes that latitude ranges from +90 at the North Pole, to 0 at the Equator, to -90 at the South Pole. It also assumes that the longitude values range from -180 in the western hemisphere to 0 at the Prime Meridian to +180 in the eastern hemisphere. It calculates the great circle distance between the two points.

Parameters:
other - the other Location
Returns:
the distance in meters between the two Locations

update

public void update(hw6.Location loc)
Update the current location based on the Location object provided.

Parameters:
loc - the Location from which to copy the lat and lon values.

update

public void update(double lat,
                   double lon)
Update the current location based on the values provided.

Parameters:
lat - the latitude. This value must be from -90. to +90. and this method throws a RuntimeException if that is not true.
lon - the longitude. This value can range from -180. to +180. and this method throws a RuntimeException if that is not true.

clone

public java.lang.Object clone()
Create a copy of this Location object. A shallow copy is okay here, because the only instance variables are primitive types and so Object.clone() is sufficient and we don't need to do any deep copying.

Overrides:
clone in class java.lang.Object
Returns:
a clone of this Location instance

toString

public java.lang.String toString()
Provide a String representation of our location.

Overrides:
toString in class java.lang.Object

main

public static void main(java.lang.String[] arg)
Test harness for this class.