Class Point

java.lang.Object
  extended by Point
All Implemented Interfaces:
java.lang.Cloneable

public class Point
extends java.lang.Object
implements java.lang.Cloneable

A Point object represents a 2-D (x, y) pair in the Cartesian plane.

Version:
1.0
Author:
Marty Stepp

Constructor Summary
Point()
          Constructs a new point object at the origin, (0, 0).
Point(int x, int y)
          Constructs a new point with the given x/y coordinates.
 
Method Summary
 Point clone()
          Creates a copy of this Point object.
 double distance(Point p)
          Returns the direct distance between this point and the given other point.
 boolean equals(java.lang.Object o)
          Returns whether o refers to a Point object with the same x/y coordinates as this Point.
 int getX()
          Returns the x-coordinate of this point.
 int getY()
          Returns the y-coordinate of this point.
 java.lang.String toString()
          Returns a string representation of this point, such as "(3, -2)".
 void translate(int dx, int dy)
          Shifts the x/y position of this point by the given offsets.
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Point

public Point()
Constructs a new point object at the origin, (0, 0).


Point

public Point(int x,
             int y)
Constructs a new point with the given x/y coordinates.

Parameters:
x - the x-coordinate to use
y - the x-coordinate to use
Method Detail

clone

public Point clone()
Creates a copy of this Point object.

Overrides:
clone in class java.lang.Object
Returns:
the copy created

distance

public double distance(Point p)
Returns the direct distance between this point and the given other point.

Parameters:
p - the point to measure against
Returns:
the direct distance as a real number
Throws:
java.lang.NullPointerException - if p is null

equals

public boolean equals(java.lang.Object o)
Returns whether o refers to a Point object with the same x/y coordinates as this Point.

Overrides:
equals in class java.lang.Object
Parameters:
o - the object to compare against
Returns:
true if o refers to a Point object with the same x/y coordinates as this Point; otherwise false

getX

public int getX()
Returns the x-coordinate of this point.

Returns:
the point's x-coordinate

getY

public int getY()
Returns the y-coordinate of this point.

Returns:
the point's y-coordinate

translate

public void translate(int dx,
                      int dy)
Shifts the x/y position of this point by the given offsets.

Parameters:
dx - the x-offset by which to shift
dy - the y-offset by which to shift

toString

public java.lang.String toString()
Returns a string representation of this point, such as "(3, -2)".

Overrides:
toString in class java.lang.Object