//                 Simple Point class for final section 
//                 of Scientific Programming


public class Point {
    
    private double xLoc, yLoc, zLoc;       // The acutal position (internal) 

	
    //              Basic constructors (supply two)

    public Point(double x, double y, double z) {  // Set point to x,y,z
	xLoc = x;
	yLoc = y;
	zLoc = z;
    }

    public Point() {                              // Set point to 0,0,0
	xLoc = 0.0;
	yLoc = 0.0;
	zLoc = 0.0;
    }

    //             The get Methods to return x,y,z

    public double getX() {                                  // Return x value.
	return this.xLoc;
    }
    public double getY() {
	return this.yLoc;
    }
    public double getZ() {
	return this.zLoc;
    }

    //          Method to get distant from Origin


    public double fromOrigin() {
	return Math.sqrt(xLoc*xLoc + yLoc*yLoc + zLoc*zLoc);
    } 

    //           Method to return Distance between two points

    public double distance(Point p) {
	double xDelta = this.xLoc - p.xLoc;
	double yDelta = this.xLoc - p.yLoc;
	double zDelta = this.zLoc - p.zLoc;

	return Math.sqrt(xDelta*xDelta + yDelta*yDelta + zDelta*zDelta);
    }

    //           Method to add to points together

    public Point add(Point p)
    {
	double x = this.xLoc + p.xLoc;
	double y = this.yLoc + p.yLoc;
	double z = this.zLoc + p.zLoc;
	return new Point(x,y,z);             // Return a new point
    }

    //          String method to overload standard toSring()

    public String toString() {               // MUST be called toString()
	return String.format("(%g,%g,%g)", this.xLoc,this.yLoc,this.zLoc);

	//   Note: use of "this" is optional here since there can
	//   be no confusion. It is good programming style to add
	//   "this" to make the code clearer.
       }

}
