-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTPoint.java
44 lines (38 loc) · 1 KB
/
TPoint.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
//TPoint.java
/*
This is just a trivial "struct" type class --
it simply holds an int x/y point for use by Tetris,
and supports equals() and toString().
We'll allow public access to x/y, so this
is not an object really.
*/
public class TPoint {
public int x;
public int y;
// Creates a TPoint based in int x,y
public TPoint(int x, int y) {
// questionable style but convenient --
// params with same name as ivars
this.x = x;
this.y = y;
}
// Creates a TPoint, copied from an existing TPoint
public TPoint(TPoint point) {
this.x = point.x;
this.y = point.y;
}
// Standard equals() override
public boolean equals(Object other) {
// standard two checks for equals()
if (this == other) return true;
if (!(other instanceof TPoint)) return false;
// check if other point same as us
TPoint pt = (TPoint)other;
return(x==pt.x && y==pt.y);
}
// Standard toString() override, produce
// human-readable String from object
public String toString() {
return "(" + x + "," + y + ")";
}
}