8a41df6ad2281a454b63af19135e2c97aea4a3c4
2 import java
.io
.FileNotFoundException
;
4 import java
.util
.Scanner
;
12 private String csvFile
= "data/countries.csv";
17 public Country(String name
) {
19 initCountryFromCSV(name
);
22 public Country(String name
, String region
, double lat
, double lng
, String flag
) {
30 public void setName(String name
) {
34 public String
getName() {
38 public void setRegion(String region
) {
42 public void setLat(double lat
) {
46 public double getLat() {
50 public void setLng(double lng
) {
54 public double getLng() {
58 public void setFlag(String flag
) {
62 public String
getFlag() {
66 public int distanceTo(Country country
) {
67 if ((this.getLat() == country
.getLat()) && (this.getLng() == country
.getLng())) {
70 double theta
= this.getLng() - country
.getLng();
71 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
));
72 dist
= Math
.acos(dist
);
73 dist
= Math
.toDegrees(dist
);
74 dist
= dist
* 60 * 1.1515;
76 dist
= dist
* 1.609344;
77 return dist
.intValue();
81 private void initCountryFromCSV(String name
) {
82 Scanner scanner
= null;
84 scanner
= new Scanner(new File(csvFile
));
85 } catch (FileNotFoundException e
) {
88 while (scanner
.hasNext()) {
89 List
<String
> line
= CSVUtils
.parseLine(scanner
.nextLine());
90 String countryList
= line
.get(0);
91 String
[] countryArray
= countryList
.split(",");
92 String latLng
= line
.get(16);
93 String
[] latLngArray
= latLng
.split(",");
94 if (countryArray
[1].equals(name
)) {
95 setRegion(line
.get(12));
96 setLat(Double
.parseDouble(latLngArray
[0]));
97 setLng(Double
.parseDouble(latLngArray
[1]));
104 public String
toString() {
106 "name='" + name
+ '\'' +
107 ", region='" + region
+ '\'' +