-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathAddress.java
More file actions
41 lines (30 loc) · 975 Bytes
/
Address.java
File metadata and controls
41 lines (30 loc) · 975 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package first;
public class Address {
private double latitude;
private double longitude;
private String written_address;
public Address(double latitude, double longitude, String written_address) {
this.latitude = latitude;
this.longitude = longitude;
this.written_address = written_address;
}
public double getLatitude() {
return latitude;
}
public double getLongitude() {
return longitude;
}
public String getWrittenAddress() {
return written_address;
}
public double distanceFrom(Address otherAddress) {
double lat1 = (this.latitude);
double lon1 = (this.longitude);
double lat2 = (otherAddress.getLatitude());
double lon2 = (otherAddress.getLongitude());
double dLat = lat2 - lat1;
double dLon = lon2 - lon1;
double distance = Math.sqrt(Math.pow(dLat, 2) + Math.pow(dLon, 2));
return distance;
}
}