X-Git-Url: https://git.piment-noir.org/?p=Persons_Comparator.git;a=blobdiff_plain;f=src%2FCountry.java;h=7f2486bae6be22d6ed02628bdac1ab12baf8c422;hp=8a41df6ad2281a454b63af19135e2c97aea4a3c4;hb=b340a28fcacc7c2d230897ec810b88718b954f42;hpb=dcde664f250e05357878e3802a997a81ba93c61a diff --git a/src/Country.java b/src/Country.java index 8a41df6..7f2486b 100644 --- a/src/Country.java +++ b/src/Country.java @@ -68,7 +68,9 @@ public class Country { return 0; } else { 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)); + 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; @@ -85,18 +87,23 @@ public class Country { } catch (FileNotFoundException e) { e.printStackTrace(); } + boolean found = false; while (scanner.hasNext()) { List line = CSVUtils.parseLine(scanner.nextLine()); String countryList = line.get(0); String[] countryArray = countryList.split(","); String latLng = line.get(16); String[] latLngArray = latLng.split(","); - if (countryArray[1].equals(name)) { + if (countryArray[0].equals(name)) { + found = true; setRegion(line.get(12)); setLat(Double.parseDouble(latLngArray[0])); setLng(Double.parseDouble(latLngArray[1])); + setFlag(line.get(21)); } } + if (!found) + System.out.println("Country " + name + " not found"); scanner.close(); }