forked from Yehudit-Brickner/OOP2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGeo.java
78 lines (64 loc) · 1.6 KB
/
Geo.java
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
public class Geo implements GeoLocation {
private double x;
private double y;
private double z;
//this class is the location of each node .
public Geo (double x,double y,double z){
this.x=x;
this.y=y;
this.z=z;
}
public Geo (Geo v){
this.x=v.x();
this.y=v.y();
this.z=v.z();
}
//this constructor get string that have the location and make from it double of x/y/z.
public Geo (String s){
int a = 0;
int b=0;
String x = "";
String y ="";
String z = "";
int k=0;
for (int i =0 ; i<2;i++){
if(i==1)k++;
while(s.charAt(k)!= ','){
k++;
}
if(a==0){
a=k;
}else{
b=k;
}
}
x=s.substring(0,a);
y=s.substring(a+1,b);
z=s.substring(b+1,s.length());
this.x = Double.parseDouble(x);
this.y = Double.parseDouble(y);
this.z = Double.parseDouble(z);
}
@Override
public double x() {
return this.x;
}
@Override
public double y() {
return this.y;
}
@Override
public double z() {
return this.z;
}
@Override
// function that return the distance between 2 geos
public double distance(GeoLocation g) {
double one = Math.pow((g.x()-this.x),2);
double two =Math.pow((g.y()-this.y),2);
double three = Math.pow((g.z()-this.z),2);
double final1 = one+two+three;
final1 = Math.sqrt(final1);
return final1;
}
}