-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPoint.java
More file actions
60 lines (47 loc) · 1.27 KB
/
Point.java
File metadata and controls
60 lines (47 loc) · 1.27 KB
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
public class Point {
private double x;
private double y;
public Point(double x, double y) {
this.x = x;
this.y = y;
}
public Point() {
this.x = 0.0;
this.y = 0.0;
}
public double getX() {
return x;
}
public double getY() {
return y;
}
public void setX(double x) {
this.x = x;
}
public void setY(double y) {
this.y = y;
}
public String toString() {
return "(" + x + ", " + y + ")";
}
public double distance(double x2, double y2) {
double x1 = this.getX();
double y1 = this.getY();
double result = Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));
return result;
}
public double distance() {
double x1 = this.getX();
double y1 = this.getY();
double result = Math.sqrt(Math.pow(x1 - 0, 2) + Math.pow(y1 - 0, 2));
return result;
}
public double distance(Point p) {
double x1 = this.getX();
double y1 = this.getY();
double x2 = p.getX();
double y2 = p.getY();
double result = Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));
return result;
}
}