Location.java /**
A class to describe the location of a place on Earth.
*/
public class Location
{
private double latid;
private double longit;
private static final double EARTH_RADIUS = 6371;
/**
Construct a location with a given latitude and longitude (in degrees)
*/
public Location(double latitude, double longitude)
{
. . .
}
public double getLongitudeInRadians() { return longit; }
public double getLatitudeInRadians() { return latid; }
/**
Gets the distance between two locations in kilometers
@param other another location
@return the distance between this location and other
*/
public double getDistance(Location other)
{
. . .
}
}
Use the following file:
LocationTester.java
public class LocationTester
{
public static void main(String[] args)
{
// Compute distance from Atlanta, Georgia to San Francisco, California
Location atlanta = new Location(33.755, -84.39);
Location sanFrancisco = new Location(37.7793, -122.4192);
System.out.printf("%8.1f kilometers\n", atlanta.getDistance(sanFrancisco));
System.out.println("Expected: 3436.5 kilometers");
// Should be the same distance either way
System.out.printf("%8.1f kilometers\n", sanFrancisco.getDistance(atlanta));
System.out.println("Expected: 3436.5 kilometers");
}
}