-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPoint.java
67 lines (56 loc) · 1.19 KB
/
Point.java
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
/**
*
* @author Stephanie Engelhardt
*
*/
public class Point implements Comparable<Point>{
private int x;
private int y;
public Point(){ //default constructor
// x and y get default value 0
}
public Point(int x, int y){
this.x = x;
this.y = y;
}
public Point(Point p) { // copy constructor
x = p.getX();
y = p.getY();
}
public int getX() {
return x;
}
public int getY(){
return y;
}
@Override
public boolean equals(Object obj){
if (obj == null || obj.getClass() != this.getClass()){
return false;
}
Point other = (Point) obj;
return x == other.x && y == other.y;
}
/**
* Compare this point with a second point q in the left-to-right order.
* @param q
* @return -1 if this.x < q.x || (this.x == q.x && this.y < q.y)
* 0 if this.x == q.x && this.y == q.y
* 1 otherwise
*/
public int compareTo(Point q){
if(q.getX()==this.x && q.getY()==this.y)
return 0;
else if(this.getX()<q.getX()||(this.getX()==q.getX() && this.getY() < q.getY()))
return -1;
else
return 1;
}
/**
* Output a point in the standard form (x, y).
*/
@Override
public String toString() {
return "("+x+","+y+")";
}
}