X-Git-Url: https://git.piment-noir.org/?p=Persons_Comparator.git;a=blobdiff_plain;f=src%2FCountry.java;fp=src%2FCountry.java;h=8a41df6ad2281a454b63af19135e2c97aea4a3c4;hp=5a57362f07d6a2006ba07b75436d13cd426ac133;hb=9f1e899962a92c9c1b8d3713eca0524964465014;hpb=a9c1e3ed70af9286718689befc35aae0c2eeb49c diff --git a/src/Country.java b/src/Country.java index 5a57362..8a41df6 100644 --- a/src/Country.java +++ b/src/Country.java @@ -11,6 +11,14 @@ public class Country { private String flag; private String csvFile = "data/countries.csv"; + public Country() { + } + + public Country(String name) { + setName(name); + initCountryFromCSV(name); + } + public Country(String name, String region, double lat, double lng, String flag) { setName(name); setRegion(region); @@ -19,12 +27,6 @@ public class Country { setFlag(flag); } - public Country(String name) { - setName(name); - loadCSVOneCountry(this.name); - - } - public void setName(String name) { this.name = name; } @@ -62,11 +64,11 @@ public class Country { } public int distanceTo(Country country) { - if ((this.lat == country.lat) && (this.lng == country.lng)) { + if ((this.getLat() == country.getLat()) && (this.getLng() == country.getLng())) { 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)); + double theta = this.getLng() - country.getLng(); + Double dist = Math.sin(Math.toRadians(this.getLat())) * Math.sin(Math.toRadians(country.getLat())) + Math.cos(Math.toRadians(this.getLat())) * Math.cos(Math.toRadians(country.getLat())) * Math.cos(Math.toRadians(theta)); dist = Math.acos(dist); dist = Math.toDegrees(dist); dist = dist * 60 * 1.1515; @@ -76,7 +78,7 @@ public class Country { } } - public void loadCSVOneCountry(String name) { + private void initCountryFromCSV(String name) { Scanner scanner = null; try { scanner = new Scanner(new File(csvFile)); @@ -89,8 +91,6 @@ public class Country { String[] countryArray = countryList.split(","); String latLng = line.get(16); String[] latLngArray = latLng.split(","); - - if (countryArray[1].equals(name)) { setRegion(line.get(12)); setLat(Double.parseDouble(latLngArray[0])); @@ -98,14 +98,8 @@ public class Country { } } scanner.close(); - /*Utils.displayArrayList(countryArrayListOceania); - Utils.displayArrayList(countryArrayListAfrica); - Utils.displayArrayList(countryArrayListAmericas); - Utils.displayArrayList(countryArrayListAsia); - Utils.displayArrayList(countryArrayListEurope);*/ } - @Override public String toString() { return "Country{" +