/** Point: find distance between two points
 * 
 * @author: CPSC 111 Jan 2010
 * Date: Wed Feb 3 2010
 * 
 * We started this code Friday, and have now tested and refined it. On Wednesday, we commented with javadoc.
 * 
 */

public class Point2 {

    private double x;
    private double y;


    // could we just name the input parameters by the real names? yes,
    // if we use "this" to distinguish between the fields of the
    // object and the passed-in parameters
    
    public Point2(double x, double y) {
	this.x = x;
	this.y = y;
    }
    

    public double getX() {
	return x;
    }
    public double getY() {
	return y;
    }

/** 
 * @param otherPoint point to calculate distance from
 * @return distance between this point and otherPoint
 */
    public double distanceBetween(Point2 otherPoint) {

	double distance = Math.sqrt(
	     Math.pow(otherPoint.getX() - x,2) +
	     Math.pow(otherPoint.getY() - y,2)
	     );
	// do we have to use Math.sqrt? or just sqrt?
	// yes, we do have to use Math.sqrt!
	// using Math.pow lets us avoid duplicate code of x*x
	return distance;
    }

    public double distanceToOrigin() {
	// let's avoid copy/paste and then tweaking code!
	// reusing existing code to do this.
	Point2 origin = new Point2(0,0);
	return distanceBetween(origin);
    }

}
