Class Position

java.lang.Object
student.micro.battleship.Position

public class Position extends Object
Represents an (x, y) position. Positions are immutable, so the x and y values can only be set when the position is created.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Position(int x, int y)
    Create a new (x, y) position.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    equals(Object other)
    Compare this position object to another to determine if they represent the same (x, y) location.
    int
    Get the x-coordinate value for this position.
    int
    Get the y-coordinate value for this position.
    Generate a human-readable representation of this position as "(x, y)".

    Methods inherited from class java.lang.Object

    getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Position

      public Position(int x, int y)
      Create a new (x, y) position.
      Parameters:
      x - The horizontal x-coordinate value.
      y - The vertical y-coordinate value.
  • Method Details

    • getX

      public int getX()
      Get the x-coordinate value for this position.
      Returns:
      The position's x value.
    • getY

      public int getY()
      Get the y-coordinate value for this position.
      Returns:
      The position's y value.
    • equals

      public boolean equals(Object other)
      Compare this position object to another to determine if they represent the same (x, y) location.
      Overrides:
      equals in class Object
      Returns:
      True if this position's (x, y) is the same as the other object's.
    • toString

      public String toString()
      Generate a human-readable representation of this position as "(x, y)".
      Overrides:
      toString in class Object
      Returns:
      A string value of the form "(x, y)" containing this position's coordinates.