Package application.model
Class Coordinate
java.lang.Object
application.model.Coordinate
- All Implemented Interfaces:
java.lang.Comparable<Coordinate>
public class Coordinate extends java.lang.Object implements java.lang.Comparable<Coordinate>
Represents a coordinate on a 2D plane.
Note that the Coordinate class is immutable.
-
Constructor Summary
Constructors Constructor Description Coordinate()
Initialises a coordinate at (0, 0)Coordinate(int x, int y)
Initialises a coordinate at (x, y) -
Method Summary
Modifier and Type Method Description Coordinate
add(Coordinate coordinate)
Adds 2 coordinates.int
compareTo(Coordinate o)
boolean
equals(java.lang.Object o)
int
getX()
Gets the x-coordinateint
getY()
Gets the y-coordinateint
hashCode()
Coordinate
subtract(Coordinate coordinate)
Adds 2 coordinates.java.lang.String
toString()
-
Constructor Details
-
Coordinate
public Coordinate()Initialises a coordinate at (0, 0) -
Coordinate
public Coordinate(int x, int y)Initialises a coordinate at (x, y)- Parameters:
x
- The x-coordinatey
- The y-coordinate
-
-
Method Details
-
getX
public int getX()Gets the x-coordinate- Returns:
- Returns the x-coordinate
-
getY
public int getY()Gets the y-coordinate- Returns:
- Returns the y-coordinate
-
add
Adds 2 coordinates. For example, (2, 3) + (1, 4) = (2 + 1, 3 + 4) = (3, 7).- Parameters:
coordinate
- The coordinate to add- Returns:
- Returns the new coordinate
-
subtract
Adds 2 coordinates. For example, (2, 3) - (1, 4) = (2 - 1, 3 - 4) = (1, -1).- Parameters:
coordinate
- The coordinate to subtract- Returns:
- Returns the new coordinate
-
compareTo
- Specified by:
compareTo
in interfacejava.lang.Comparable<Coordinate>
-
equals
public boolean equals(java.lang.Object o)- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()- Overrides:
toString
in classjava.lang.Object
-