-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyPoint.java
More file actions
52 lines (46 loc) · 1.26 KB
/
MyPoint.java
File metadata and controls
52 lines (46 loc) · 1.26 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
class MyPoint{
private int x, y;
MyPoint() {
x = 0;
y = 0;
}
MyPoint(int x, int y){
this.x = x;
this.y = y;
}
void setXY(int x, int y){
this.x = x;
this.y = y;
}
int[] getXy(){
int[] arr = {x,y};
return arr;
}
public String toString(){
return "(" + x + "," + y + ")";
}
void distance(int x2, int y2){
double value = Math.sqrt((x2-x)*(x2-x) + (y2-y)*(y2-y));
System.out.println("distance between" + " (" + x + "," + y + ") ,"+" (" + x2 + "," +y2 +") =>"+value);
}
}
class TestMyPoint{
public static void main(String[] args) {
MyPoint a1 = new MyPoint(); // default
int[] x = a1.getXy();
for(int i = 0; i < x.length; i ++){
System.out.println(x[i]);
}
a1.setXY(10, 15);
a1.distance(20, 30);
System.out.println(a1);
System.out.println("*****************************************");
MyPoint a2 = new MyPoint(1,2);
// x = a1.getXy();
// for(int i = 0; i < x.length; i ++){
// System.out.println(x[i]);
// }
a2.distance(2, 4);
System.out.println(a2);
}
}