X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2FCountry.java;h=c663ff0af66b22c2c8c9bdd22845f51cbb434d00;hb=e16e3b1587a729dd1e2d39bd4426831136376aa7;hp=8b711084bb81e145f7ac8317a83cafdbd0c9b950;hpb=f56708fa0a19755ac5ec0313d9ee9c45a9aef0ce;p=Persons_Comparator.git diff --git a/src/Country.java b/src/Country.java index 8b71108..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); @@ -16,6 +18,10 @@ public class Country { this.name = name; } + public String getName() { + return name; + } + public void setRegion(String region) { this.region = region; } @@ -28,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{" +