Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Problem. (Geo Location) Implement an immutable date type location in Location.ja

ID: 3757298 • Letter: P

Question

Problem.(Geo Location) Implement an immutable date type location in Location.java that represents a location on Earth and supports the following API:

Problem 3. (Geo Location) Implement an immutable data type Location in Location.java that represents a location on Earth and supports the following API method Location(String loc, double lat, double lon) double distanceTo (Location that) boolean equals(Location that) String toString(O description construct a new location given its name, latitude, and longitude values the great-circle distance between this location and that is this location the same as that? a string representation of the location, in "loc (lat, lon) format t See Problem 4 of Homework 1 for formula 1 of 3

Explanation / Answer

public class Location { private final String loc; private final double lat; private final double lon; public Location(String loc, double lat, double lon) { this.loc = loc; this.lat = lat; this.lon = lon; } public double distanceTo(Location that) { return Math.sqrt(Math.pow(lat-that.lat, 2) + Math.pow(lon-that.lon, 2)); } public boolean equals(Location that) { return loc.equals(that.loc) && lat==that.lat && lon==that.lon; } @Override public String toString() { return loc + "(" + lat + "," + lon + ")"; } // Use test client you have here. }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote