/** Final draft of the Point class for a 2D mathematical point. 
 * Created in class on Jan 26, improved on Jan 31, and finished Feb 2. 
 *
 * @author CPSC 111, Section 206, Spring 05-06
 * @version Feb 2 2006
 *
 */


public class Point {

    private int xCoord; /** X coordinate of the Point */
    private int yCoord; /** Y coordinate of the Point */

    /**
     * Default constructor.
     */
    public Point()
    {
    }
    
    /**
     * Point Constructor with initialization 
     * @param x initial X location of point
     * @param y initial Y location of point
     */
    public Point(int x, int y)
    {
        setPosition(x,y);
    }

    /**
     * Set the position of the point
     * @param x new X position
     * @param y new Y position
     */
    public void setPosition(int x, int y)
    {
        xCoord = x;
        yCoord = y;
    }

    /**
     * Translate the point to a new location
     * @param deltaX amount to move in X
     * @param deltaY amount to move in Y
     */
    public void translate(int deltaX, int deltaY)
    {
        xCoord = xCoord + deltaX;
        yCoord = yCoord + deltaY;
    }

    /**
     *  Get the X value of the point
     * @return X coordinate of point
     */
    public int getX()
    {
        return xCoord;
    }

    /**
     * Get the Y value of the point
     * @return Y coordinate of point
     */
    public int getY()
    {
        return yCoord;
    }

    /** 
     *   Compute 2D distance from origin to point.
     */
    public double distanceTo() {
                return Math.sqrt(Math.pow(xCoord,2) + yCoord*yCoord);
    }

    /** 
     *   Compute 2D distance between this and otherPoint.
     *   @param otherPoint second point in distance calculation
     */
    public double distanceBetween(Point otherPoint) {
                int xDelta = otherPoint.getX() - this.xCoord;
                int yDelta = otherPoint.getY() - this.yCoord;
                Point newPoint = new Point(xDelta, yDelta);
                double newDistance = newPoint.distanceTo();     
                return newDistance;
    }
}

