/** Point: second draft of the Point class
 * Author: CPSC 111, Section 206, Spring 05-06
 * Date: Jan 31 2006
 *
 * This class is a 2D mathematical point, created in class on Jan 26 and improved
 * on Jan 31. We have tested construction, translate, and distanceTo. 
 * The distanceBetween method is still untested.
 */


public class Point {

    private int xCoord;
    private int yCoord;

    public Point()
    {
    }
    
    public Point(int x, int y)
    {
	setPosition(x,y);
    }

    public void setPosition(int x, int y)
    {
	xCoord = x;
	yCoord = y;
    }

    public void translate(int deltaX, int deltaY)
    {
	xCoord = xCoord + deltaX;
	yCoord = yCoord + deltaY;
    }

    public int getX()
    {
	return xCoord;
    }

    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) {
    		double xDelta = otherPoint.getX() - this.xCoord;
    		double yDelta = otherPoint.getY() - this.yCoord;
    		Point newPoint = new Point(xDelta, yDelta);
    		return newPoint.distanceTo();	
    }
}
