A position on the planet Earth is specified by latitude and longitude (in degrees). The distance between two points on a sphere can be calculated with the following formula, where latitude and longitude are in radians and r is the radius of the sphere:

distance = r * arccos(sin(latitude1) * sin(latitude2) + cos(latitude1) * cos(latitude2) * cos(longitude1 - longitude2))

The radius of the planet Earth is 6371 km

Your task is to compute the distance between two Location objects.

Complete the following file:

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");
   }
}