/* Author: CPSC 111 Jan 2010
 * Date: Mon Feb 1 2010
 * Point: find distance between two points
 * 
 * We started this code Friday, and have now tested and refined it.
 *
 */

public class Point2 {

    private double x;
    private double y;

    public Point2(double inX, double inY) {
	x = inX;
	y = inY;
    }

    // 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 Point(double x, double y) {
	this.x = x;
	this.y = y;
    }
    */

    //    public Point(x,y) {} // can we do this? no, too bad...

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


    public double distanceBetween(Point2 otherPoint) {

	double distance = Math.sqrt(
	     (otherPoint.getX() - x)*(otherPoint.getX() - x) +
	     (otherPoint.getY() - y)*(otherPoint.getY() - y)
	     );
	// do we have to use Math.sqrt? or just sqrt?
	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);
    }

}
