Repository navigation
Expand file tree
/
Copy pathPoint.java
More file actions
67 lines (55 loc) · 1.66 KB
/
Copy pathPoint.java
File metadata and controls
67 lines (55 loc) · 1.66 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
61
62
63
64
65
66
67
package domain;
public class Point {
private int x;
private int y;
public Point(int x, int y) throws Exception {
if (!((x >= 0 && x < 25) && (y >= 0 && y < 25))) {
throw new IllegalArgumentException("입력 범위를 초과하였습니다. 0~24");
}
this.x = x;
this.y = y;
}
public static Point getPoint(int x, int y) throws Exception {
return new Point(x, y);
}
public static Point getPoint(String x, String y) throws Exception {
if (x == null || x == null) {
throw new Exception("(선, 삼각형, 직사각형)을 만들 수 없는 좌표입니다.");
}
return getPoint(Integer.parseInt(x), Integer.parseInt(y));
}
public Double getDistance(Point otherPoint) {
int aX = this.getX();
int aY = this.getY();
int bX = otherPoint.getX();
int bY = otherPoint.getY();
return Math.sqrt(Math.pow((aX - bX), 2) + Math.pow((aY - bY), 2));
}
public int getX() {
return x;
}
public int getY() {
return y;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Point point = (Point) o;
if (this.x == point.getX() && this.y == point.getY()) {
return true;
}
return false;
}
@Override
public int hashCode() {
int result = 17;
result = 31 * result + this.x;
result = 31 * result + this.y;
return result;
}
@Override
public String toString() {
return "x : " + this.x + ", y : " + this.y;
}
}