- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPoint.java
More file actions
Latest commit
28 lines (20 loc) · 1.01 KB
/
Copy pathPoint.java
File metadata and controls
28 lines (20 loc) · 1.01 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
packageweek02.intermediate;
publicclassPoint {
intx , y;
Point(intx, inty){
this.x = x;
this.y = y;
}
doublegetDistance(Pointother){
doubledx = this.x - other.x;
doubledy = this.y - other.y;
returnMath.sqrt(dx * dx + dy * dy);
}
// 19단계(응용): Point 클래스와 거리 계산 메서드
// 문제: Point.java에 int x, y 좌표를 멤버 변수로 만드세요. 다른 Point 객체를 매개변수로 받아
// 현재 점과의 거리를 계산하여 double로 리턴하는 getDistance(Point other) 메서드를 구현하세요.
// PointTest.java에서 두 Point 객체를 만들고 한 객체에서 getDistance를 호출하여 결과를 출력하세요.
// 핵심 사고: 클래스를 이용해 현실의 개념(좌표)을 모델링하고, 해당 객체들의 데이터를 이용해 연산하는 메서드를
// 클래스 내부에 구현합니다.
// 힌트: 클래스, 메서드, 객체를 매개변수로 전달, Math.sqrt, Math.pow, return
}