-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPoint.java
More file actions
38 lines (35 loc) · 751 Bytes
/
Point.java
File metadata and controls
38 lines (35 loc) · 751 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
public class Point{
private double x,y;
public Point(double X, double Y){
x=X;
y=Y;
}
public Point(Point p){
x= p.getX();
y= p.getY();
}
public double getX(){
return x;
}
public double getY(){
return y;
}
public void setX(double x2){
x = x2;
}
public void setY(double y2){
y = y2;
}
public String toString(){
return "(" + x + "," + y + ")";
}
public Point copy(){
return new Point(x, y);
}
public double distanceTo(Point other){
return Math.sqrt(Math.pow(x - other.getX(), 2) + Math.pow(y - other.getY(), 2));
}
public static double distance(Point p1, Point p2){
return Math.sqrt(Math.pow(p1.getX() - p2.getX(), 2) + Math.pow(p1.getX() - p2.getY(), 2));
}
}