0

```
public class Formal2{
String name;
double longitude;
double latitude;
double distanceFrom;
public double getLongitude(){
return longitude;
}
public void setLongitude(double longitude){
this.longitude = longitude;
}
public double getLatitude(){
return latitude;
}
public void setLatitude(double latitude){
this.latitude = latitude;
}
public String getName(){
return name;
}
public void setName(String name) {
this.name = name;
}
public double getDistanceFrom(){
return distanceFrom;
}
public void setDistanceFrom(double distanceFrom){
this.distanceFrom=distanceFrom;
}
public String toString(){
return ("City Name = " + name + "\nLatitude = " + latitude + "\nLongitude = " + longitude);
}
}
import java.lang.Math;
public class GreatCircleDistance{
// CONSTANTS USED INTERNALLY
final double DEGREES_TO_RADIANS = ( Math.PI/180.0 );
// Mean radius in KM
final double EARTH_RADIUS = 6371.0;
/** Method to compute Great Circle distance between
* two points. Please note that this algorithm
* assumes the Earth to be a perfect sphere, whereas
* in fact the equatorial radius is about 30Km
* greater than the Polar.
*
* @param alt other point to compute distance to
* @return The distance in Kilometres
*/
public double GreatCircleDistance(lat, lon, alt) {
// There is no real reason to break this lot into
// 4 statements but I just feel it's a little more
// readable
double p1 = Math.cos(lat)*Math.cos(lon)
*Math.cos(alt.lat)*Math.cos(alt.lon);
double p2 = Math.cos(lat)*Math.sin(lon)
*Math.cos(alt.lat)*Math.sin(alt.lon);
double p3 = Math.sin(lat)*Math.sin(alt.lat);
return(Math.acos(p1+p2+p3)*EARTH_RADIUS);
}
}
public class Main {
/** Creates a new instance of Main */
public Main() {
}
/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
Formal2 l1 = new Formal2();
double longitude;
double latitude;
String name;
l1.name = "Toronto"; //set state variables
l1.longitude = 2.2;
l1.latitude = 1.6;
longitude = l1.getLongitude(); //calculate longitude
latitude = l1.getLatitude(); //calculate latitude
name = l1.getName();
System.out.println(l1);
}
}
```