so I have Location class, and a radio class(the radio class contains the coordinates). Basically for a program I am writing I need the location to take the coordinates from the radio class, and use the distance formula for the 2 sets of coordinates. Location:
public class Location {
private double lat, lon;
public Location (double lat, double lon){
this.lat=lat;
this.lon=lon;
}
public Location (){
this.lat=0.0;
this.lon=0.0;
}
public void setLat(double lat){
this.lat=lat;
}
public void setLon(double lon){
this.lon=lon;
}
public double Distance (double lat1, double lon1, double lat2, double lon2) {
lat1 = Math.toRadians(lat1);
lon1 = Math.toRadians(lon1);
lat2 = Math.toRadians(lat2);
lon2 = Math.toRadians(lon2);
double cosLat2 = Math.cos(lat2);
double sinLonChange = Math.sin(lon2-lon1);
double cosLat1 = Math.cos(lat1);
double sinLat2 = Math.sin(lat2);
double sinLat1 = Math.sin(lat1);
double cosLonChange = Math.cos(lon2-lon1);
double a = Math.pow((cosLat2*sinLonChange), 2);
double b = Math.pow(((cosLat1*sinLat2)-(sinLat1*cosLat2*cosLonChange)), 2);
double c = (sinLat1*sinLat2)+(cosLat1*cosLat2*cosLonChange);
double spherDistance = Math.atan(Math.sqrt(a+b)/c);
double Distance = 3959 * spherDistance;
return Distance;
}
public double getLat(){
return lat;
}
public double getLon(){
return lon;
}
public double getDistance(){
return Distance;
}
public String toString(){
String dist="lat"+lat+"lon"+lon;
return dist;
}
}
and Radio:
public class Radio {
public static void main(String[] args) {
Location loc1=new Location(10,20);
Location loc2=new Location(30,40);
System.out.println(loc1.toString());
System.out.println(loc2.toString());
}
}
I should also mention that the only reason main method is in radio is because I am simply testing to see if everything works.Any help or suggestions would be greatly appreciated. Thank y'all very much!