Add a println if the country name do not exist.
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
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;
} catch (FileNotFoundException e) {
e.printStackTrace();
}
+ boolean found = false;
while (scanner.hasNext()) {
List<String> 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();
}
String programName = "Person Comparator";
ArrayList<Person> personArrayList = new ArrayList<>();
- Person person1 = new Person("Alan", "United States of America", 180, 95, "black");
+ Person person1 = new Person("Alan", "United States", 180, 95, "black");
personArrayList.add(person1);
Person person2 = new Person("Brice", "France", 190, 82, "brown");
personArrayList.add(person2);
Person person3 = new Person("Alexandre", "France", 175, 73, "green");
personArrayList.add(person3);
- Person person4 = new Person("Sophia", "Brasil", 155, 57, "blue");
+ Person person4 = new Person("Sophia", "Brazil", 155, 57, "blue");
personArrayList.add(person4);
- Person person5 = new Person("Sylvain", "Italie", 181, 75, "brown");
+ Person person5 = new Person("Sylvain", "Italy", 181, 75, "brown");
personArrayList.add(person5);
- Person person6 = new Person("Merlin", "United States of America", 210, 88, "blue");
+ Person person6 = new Person("Merlin", "United States", 210, 88, "blue");
personArrayList.add(person6);
- Person person7 = new Person("Bob", "United States of America", 162, 75, "green");
+ Person person7 = new Person("Bob", "United States", 162, 75, "green");
personArrayList.add(person7);
Person person8 = new Person("John", "United Kingdom", 176, 102, "brown");
personArrayList.add(person8);
personArrayList.add(person16);
Person person17 = new Person("Aïfa", "Mali", 149, 49, "black");
personArrayList.add(person17);
- Person person18 = new Person("Roberto", "Brasil", 168, 56, "brown");
+ Person person18 = new Person("Roberto", "Brazil", 168, 56, "brown");
personArrayList.add(person18);
Person person19 = new Person("Batista", "France", 158, 52, "black");
personArrayList.add(person19);
setDistanceFromReference(0);
}
- Person(String firstname, String country, Integer size, Integer weight, String colorEye) {
+ Person(String firstname, String countryName, Integer size, Integer weight, String colorEye) {
setFirstname(new Firstname(firstname));
- setOrigin(new Origin(country));
- setCountry(new Country(country));
+ setOrigin(new Origin(countryName));
+ setCountry(new Country(countryName));
setPersonSize(new Size(size));
setWeight(new Weight(weight));
setEye(new Eye(colorEye));
String latLng = line.get(16);
String[] latLngArray = latLng.split(",");
if (line.get(12).equals("Europe")) {
- Country c = new Country(countryArray[1], line.get(12), Double.parseDouble(latLngArray[0]), Double.parseDouble(latLngArray[1]), line.get(21));
+ Country c = new Country(countryArray[0], line.get(12), Double.parseDouble(latLngArray[0]), Double.parseDouble(latLngArray[1]), line.get(21));
countryArrayListEurope.add(c);
} else if (line.get(12).equals("Africa")) {
- Country c = new Country(countryArray[1], line.get(12), Double.parseDouble(latLngArray[0]), Double.parseDouble(latLngArray[1]), line.get(21));
+ Country c = new Country(countryArray[0], line.get(12), Double.parseDouble(latLngArray[0]), Double.parseDouble(latLngArray[1]), line.get(21));
countryArrayListAfrica.add(c);
} else if (line.get(12).equals("Americas")) {
- Country c = new Country(countryArray[1], line.get(12), Double.parseDouble(latLngArray[0]), Double.parseDouble(latLngArray[1]), line.get(21));
+ Country c = new Country(countryArray[0], line.get(12), Double.parseDouble(latLngArray[0]), Double.parseDouble(latLngArray[1]), line.get(21));
countryArrayListAmericas.add(c);
} else if (line.get(12).equals("Asia")) {
- Country c = new Country(countryArray[1], line.get(12), Double.parseDouble(latLngArray[0]), Double.parseDouble(latLngArray[1]), line.get(21));
+ Country c = new Country(countryArray[0], line.get(12), Double.parseDouble(latLngArray[0]), Double.parseDouble(latLngArray[1]), line.get(21));
countryArrayListAsia.add(c);
} else if (line.get(12).equals("Oceania")) {
- Country c = new Country(countryArray[1], line.get(12), Double.parseDouble(latLngArray[0]), Double.parseDouble(latLngArray[1]), line.get(21));
+ Country c = new Country(countryArray[0], line.get(12), Double.parseDouble(latLngArray[0]), Double.parseDouble(latLngArray[1]), line.get(21));
countryArrayListOceania.add(c);
}
}