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);
setFlag(flag);
}
- public Country(String name) {
- setName(name);
- loadCSVOneCountry(this.name);
-
- }
-
public void setName(String name) {
this.name = name;
}
}
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;
}
}
- public void loadCSVOneCountry(String name) {
+ private void initCountryFromCSV(String name) {
Scanner scanner = null;
try {
scanner = new Scanner(new File(csvFile));
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]));
}
}
scanner.close();
- /*Utils.displayArrayList(countryArrayListOceania);
- Utils.displayArrayList(countryArrayListAfrica);
- Utils.displayArrayList(countryArrayListAmericas);
- Utils.displayArrayList(countryArrayListAsia);
- Utils.displayArrayList(countryArrayListEurope);*/
}
-
@Override
public String toString() {
return "Country{" +