Question: This program extends the GeoLocation class from a previous exercise. In this problem, you will write a method called public double distanceFromInkilometers(GeoLocation other) There is



This program extends the GeoLocation class from a previous exercise. In this problem, you will write a method called public double distanceFromInkilometers(GeoLocation other) There is also a new constant to help you up at the top called KM PER MILE This method should return the distance from the current object to the GeoLocation object other passed in as a parameter. public class DistanceTester extends ConsoleProgram public static double SANFRANCISCO LONGITUDE 122.4167; public static double SAN FRANCISCO LATITUDE 37.7833; public static double NEW YORK LONGITUDE 74.0059; public static double NEW YORK LATITUDE 40.7127; te te * This program computes the distance in miles between San Francisco, California * and New York City, New York using the GeoLocation class. * After running this program, try looking it up on Google Maps. How close are we? public void run) Geolocation sf = new GeoLocation(SAN-FRANCISCO-LATITUDE, SAN-FRANCISCO-LONGITUDE); GeoLocation nyc new GeoLocation NEW YORK LATITUDE, NEW YORK LONGITUDE); double distance sf.distanceFromInKilometers(nyc); System.out.println("The distance from San Francisco to New York is " distance + "kilometers"; pblic closs Coolocation /l Earth radius in ailea public static final duble NODS-3963.1676; // Mater of klonteres Ln one e public static final double QLPEKILE- 1.60934 private double latitude; privote double longi tude * Constructs a geo locotion object with given latitudle and longi tude e/ public Geolocation(double theLatitude, double thelongl tude) lotitude thelatitude longi tude thelongi tude; public double getLatitudec) return lotitude; " returns the longi tude of this geo location public double getlongi tudeC return tongi tude: // returns a string representation of this geo location public String toStringO return "latitude:latitude ', longitude" + longitude; public double distanceFromInkitoneters(Geolocation other) /7 fitl this in. return e; /l returns the distance in mites beteeen this geo location and the given // other geo locotion public double distanceFrom(Geolocation other double lat1 Math, toRadians(tatitude) double longi Math toRadLansCLongi tude); double lot2 Moth toRodions(other lotitude)i double tongz-Math. toRadions Cather.tongitude); opply the spherical tow of cosines with o triorgle composed of the /4 tws tocations and the north pote double theCosHath, sinclot1) Moth.sinctat2) Moth,coscloti) oth cos(let?) Meth, cosclong deble arclength Moth.acos(theCos): return ortLength . RADIUS; ongl); This program extends the GeoLocation class from a previous exercise. In this problem, you will write a method called public double distanceFromInkilometers(GeoLocation other) There is also a new constant to help you up at the top called KM PER MILE This method should return the distance from the current object to the GeoLocation object other passed in as a parameter. public class DistanceTester extends ConsoleProgram public static double SANFRANCISCO LONGITUDE 122.4167; public static double SAN FRANCISCO LATITUDE 37.7833; public static double NEW YORK LONGITUDE 74.0059; public static double NEW YORK LATITUDE 40.7127; te te * This program computes the distance in miles between San Francisco, California * and New York City, New York using the GeoLocation class. * After running this program, try looking it up on Google Maps. How close are we? public void run) Geolocation sf = new GeoLocation(SAN-FRANCISCO-LATITUDE, SAN-FRANCISCO-LONGITUDE); GeoLocation nyc new GeoLocation NEW YORK LATITUDE, NEW YORK LONGITUDE); double distance sf.distanceFromInKilometers(nyc); System.out.println("The distance from San Francisco to New York is " distance + "kilometers"; pblic closs Coolocation /l Earth radius in ailea public static final duble NODS-3963.1676; // Mater of klonteres Ln one e public static final double QLPEKILE- 1.60934 private double latitude; privote double longi tude * Constructs a geo locotion object with given latitudle and longi tude e/ public Geolocation(double theLatitude, double thelongl tude) lotitude thelatitude longi tude thelongi tude; public double getLatitudec) return lotitude; " returns the longi tude of this geo location public double getlongi tudeC return tongi tude: // returns a string representation of this geo location public String toStringO return "latitude:latitude ', longitude" + longitude; public double distanceFromInkitoneters(Geolocation other) /7 fitl this in. return e; /l returns the distance in mites beteeen this geo location and the given // other geo locotion public double distanceFrom(Geolocation other double lat1 Math, toRadians(tatitude) double longi Math toRadLansCLongi tude); double lot2 Moth toRodions(other lotitude)i double tongz-Math. toRadions Cather.tongitude); opply the spherical tow of cosines with o triorgle composed of the /4 tws tocations and the north pote double theCosHath, sinclot1) Moth.sinctat2) Moth,coscloti) oth cos(let?) Meth, cosclong deble arclength Moth.acos(theCos): return ortLength . RADIUS; ongl)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
