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-coordinate
    int getY()
    Gets the y-coordinate
    int hashCode()  
    Coordinate subtract​(Coordinate coordinate)
    Adds 2 coordinates.
    java.lang.String toString()  

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • 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-coordinate
      y - 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

      public Coordinate add​(Coordinate coordinate)
      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

      public Coordinate subtract​(Coordinate coordinate)
      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

      public int compareTo​(Coordinate o)
      Specified by:
      compareTo in interface java.lang.Comparable<Coordinate>
    • equals

      public boolean equals​(java.lang.Object o)
      Overrides:
      equals in class java.lang.Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class java.lang.Object
    • toString

      public java.lang.String toString()
      Overrides:
      toString in class java.lang.Object