Coordinates of a location (x,y) in the city.
| 12 | * Coordinates of a location (x,y) in the city. |
| 13 | */ |
| 14 | public class CityLocation |
| 15 | { |
| 16 | /** The X coordinate of this location. |
| 17 | * Increasing X coordinates correspond to East, |
| 18 | * and decreasing X coordinates correspond to West. */ |
| 19 | public int x; |
| 20 | |
| 21 | /** The Y coordinate of this location. |
| 22 | * Increasing Y coordinates correspond to South, |
| 23 | * and decreasing Y coordinates correspond to North. */ |
| 24 | public int y; |
| 25 | |
| 26 | /** |
| 27 | * Constructs and initializes city coordinates. |
| 28 | */ |
| 29 | public CityLocation(int x, int y) |
| 30 | { |
| 31 | this.x = x; |
| 32 | this.y = y; |
| 33 | } |
| 34 | |
| 35 | @Override |
| 36 | public int hashCode() |
| 37 | { |
| 38 | return x*33+y; |
| 39 | } |
| 40 | |
| 41 | @Override |
| 42 | public boolean equals(Object obj) |
| 43 | { |
| 44 | if (obj instanceof CityLocation) { |
| 45 | CityLocation rhs = (CityLocation)obj; |
| 46 | return this.x == rhs.x && this.y == rhs.y; |
| 47 | } |
| 48 | else { |
| 49 | return false; |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | @Override |
| 54 | public String toString() |
| 55 | { |
| 56 | return "("+x+","+y+")"; |
| 57 | } |
| 58 | } |
nothing calls this directly
no outgoing calls
no test coverage detected