X-Git-Url: https://git.piment-noir.org/?p=Persons_Comparator.git;a=blobdiff_plain;f=src%2FCountry.java;h=c663ff0af66b22c2c8c9bdd22845f51cbb434d00;hp=2bb786a2c33d92fb2d64eb9fe6302bc1472062f4;hb=e16e3b1587a729dd1e2d39bd4426831136376aa7;hpb=822afd4fe0aa1669db1e3be57b277f8aff977254 diff --git a/src/Country.java b/src/Country.java index 2bb786a..c663ff0 100644 --- a/src/Country.java +++ b/src/Country.java @@ -1,9 +1,11 @@ +import javax.swing.*; + public class Country { private String name; private String region; private double lat; private double lng; - + private ImageIcon flag; public Country(String name, String region, double lat, double lng) { setName(name); @@ -32,6 +34,21 @@ public class Country { this.lng = lng; } + public int distanceTo(Country country) { + if ((this.lat == country.lat) && (this.lng == country.lng)) { + return 0; + } else { + double theta = this.lng - country.lng; + Double dist = Math.sin(Math.toRadians(this.lat)) * Math.sin(Math.toRadians(country.lat)) + Math.cos(Math.toRadians(this.lat)) * Math.cos(Math.toRadians(country.lat)) * Math.cos(Math.toRadians(theta)); + dist = Math.acos(dist); + dist = Math.toDegrees(dist); + dist = dist * 60 * 1.1515; + // Kilometers + dist = dist * 1.609344; + return dist.intValue(); + } + } + @Override public String toString() { return "Country{" +