Question: Need some help in Java, got stuck. Below is also my code for GeoLocation.java GeoLocation.java: public class GeoLocation { private static double radius = 3963.1676;
Need some help in Java, got stuck. Below is also my code for GeoLocation.java


GeoLocation.java:
public class GeoLocation {
private static double radius = 3963.1676; private double latitude; private double longitude; public GeoLocation() /o argument constructor { latitude = 0; longitude = 0; } public GeoLocation(double latitude,double longitude)//argument constructor { this.latitude = latitude; this.longitude = longitude; } //set and get methods for latitude and longitude public void setLatitude(double latitude) { this.latitude = latitude; } public double getLatitude() { return latitude; } public void setLongitude(double longitude) { this.longitude = longitude; } public double getLongitude() { return longitude; } public double distanceFrom(GeoLocation o)//calculate distance between two Geolocation objects { double dLat = Math.toRadians(this.latitude - o.latitude); double dLng = Math.toRadians(this.longitude - o.longitude); double a = Math.sin(dLat/2) * Math.sin(dLat/2) + Math.cos(Math.toRadians(o.latitude)) * Math.cos(Math.toRadians(o.latitude)) * Math.sin(dLng/2) * Math.sin(dLng/2); double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); double dist = (double) (radius * c);
return dist; }
}
TestGeo:
public class TestGeo {
/** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here GeoLocation loc1 = new GeoLocation(); System.out.println(" Loc1: Latitude : "+ loc1.getLatitude()); System.out.println(" Longitude : "+ loc1.getLongitude()); loc1.setLongitude(77.65); loc1.setLatitude(44.34); System.out.println(" Loc1 :Latitude : "+ loc1.getLatitude()); System.out.println(" Longitude : "+ loc1.getLongitude()); GeoLocation loc2 = new GeoLocation(34.5,56.23); System.out.println(" Loc2 : Latitude : "+ loc2.getLatitude()); System.out.println(" Longitude : "+ loc2.getLongitude()); System.out.println(" Distance from loc1 to loc2 : "+loc1.distanceFrom(loc2)); } }
We learned from lecture slides how to read a UML (Unified Modeling Language diagram. Here we use one to tell us what class name, member field attributes, and member methods to code. Write a class with the following attributes and interface specification. Here we are using the term interface to describe the public methods, while "attributes is the term given to instance field variables. Place name: String description String location GeoLocation Place(name String, desc String, latitude double, longitude double) setName(name: String) void getName0 String setDescription (desc String) void getDescription0:String setLocation( latitude double, longitude double) void setLocation( location GeoLocation) void getLocation0 GeoLocation toString0 String get IdentificationString0:String A call to print a Place object system.out.println (myPlaceobject); should return a string of the format: San Diego zoo, 2920 Zoo Drive, latitude :32.735316, longitude: 117.149046
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
