Repository navigation
Expand file tree
/
Copy pathPoint.java
More file actions
65 lines (50 loc) · 1.62 KB
/
Copy pathPoint.java
File metadata and controls
65 lines (50 loc) · 1.62 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
package model;
public class Point {
private int x;
private int y;
// IllegalArgumentException 매개변수가 의도하지 않은 상황을 유발시킬 때
// IllegalStateException 메소드를 호출하기 위한 상태가 아닐 때
public Point(int x, int y) {
if (x < 0 || x > 24) {
throw new IllegalArgumentException("0이상 또는 24 이하만 입력해주십시오.");
}
if (y < 0 || y > 24) {
throw new IllegalArgumentException("0이상 또는 24 이하만 입력해주십시오.");
}
this.x = x;
this.y = y;
}
// 항상 view 패키지가 아니면 클래스 메소드를 사용하면 안된다고 생각했었다.
//팩토리 메소드를 처음 알게 되었고, 자세히 알아보고 써봐야겠다.
public int getX() {
return x;
}
public int getY() {
return y;
}
public boolean isSameXaxis(Point point) {
return this.x == point.x;
}
public boolean isSameYaxis(Point point) {
return this.y == point.y;
}
public int minusXaxis(Point point) {
return x - point.x;
}
public int minusYaxis(Point point) {
return y - point.y;
}
public double makeLine(Point point) {
return Math.sqrt(Math.pow(minusXaxis(point), 2) + Math.pow(minusYaxis(point), 2));
}
public boolean isPassable(Point point) {
return !(isSameXaxis(point) || isSameYaxis(point));
}
@Override
public String toString() {
return "Point{" +
"x=" + x +
", y=" + y +
'}';
}
}