forked from java-tester-x/JavaExercises4
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyPoint.java
More file actions
52 lines (39 loc) · 955 Bytes
/
MyPoint.java
File metadata and controls
52 lines (39 loc) · 955 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
42
43
44
45
46
47
48
49
50
51
52
package src;
public class MyPoint {
private int x = 0;
private int y = 0;
public MyPoint() {}
public MyPoint(int x, int y) {
this.x = x;
this.y = y;
}
public int getX() {
return this.x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return this.y;
}
public void setY(int y) {
this.y = y;
}
public void setXY(int x, int y) {
this.x = x;
this.y = y;
}
public double distance(int x, int y) {
int xDiff = this.x - x;
int yDiff = this.y - y;
return Math.sqrt(xDiff*xDiff + yDiff*yDiff);
}
public double distance(MyPoint another) {
int xDiff = this.x - another.getX();
int yDiff = this.y - another.getY();
return Math.sqrt(xDiff*xDiff + yDiff*yDiff);
}
public String toString() {
return "(" + this.x + ", " + this.y + ")";
}
}