-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLocation.java
85 lines (76 loc) · 1.41 KB
/
Location.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/**
* Location class keeps track of a x-y coordinate location
*/
public class Location
{
private int x;
private int y;
/**
* Creates a location object at (0,0)
*/
public Location()
{
x = 0;
y = 0;
}
/**
* Creates a location object at (x,y)
* @param x the x coordinate
* @param y the y coordinate
*/
public Location(int x, int y)
{
this.x = x;
this.y = y;
}
/**
* Returns the x-coordinate
* @return returns the x-coordinate
*/
public int getX()
{
return x;
}
/**
* Returns the y-coordinate
* @return returns the y-coordinate
*/
public int getY()
{
return y;
}
/**
* Changes the x-coordinate
* @param x the new x-coordinate
*/
public void setX(int x)
{
this.x = x;
}
/**
* Changes the y-coordinate
* @param y the new y-coordinate
*/
public void setY(int y)
{
this.y = y;
}
/**
* Returns true if two Location objects are the same
* @param obj the other Location object to compare this to
* @return returns true if obj and this have the same x-y values
*/
public boolean equals(Object obj)
{
Location other = (Location) obj;
return other.x == x && other.y == y;
}
/**
* Returns a string containing the x-y coordinate
* @return returns a string containing the x-y coordinate
*/
public String toString()
{
return "(" + x + ", "+ y + ")";
}
}