/** * Instanced of Point3d are points in 3 dimensional space. * This version of Point3d takes explicit advantage of the * fact that it is a subclass of Object. * * Walker White * February 2, 2012 */ public class Point3d { /* These are the three coordinates. */ private double x; // x coordinate; no restrictions private double y; // y coordinate; no restrictions private double z; // z coordinate; no restrictions /** * Constructor: a point at the origin * Precondition: None */ public Point3d() { // Uses other constructor. this(0.0,0.0,0.0); } /** * Constructor: a point with given coordinates (x0,y0,z0) * Precondition: None */ public Point3d(double x0, double y0, double z0) { // primary contructor. x = x0; y = y0; z = z0; } /** Yields: this Point's x coordinate */ public double getX() { return x; } /** Assigns value to x coordinate */ public void setX(double value) { x = value; } /** Yields: this Point's y coordinate */ public double getY() { return y; } /** Assigns value to y coordinate */ public void setY(double value) { y = value; } /** Yields: this Point's z coordinate */ public double getZ() { return z; } /** Assigns value to z coordinate */ public void setZ(double value) { z = value; } /** * Overrides toString() to give a textual representation */ public String toString() { return "("+x+","+y+","+z+")"; } /** * Yields: "q has the same coordinates as p" * Overrides equals() so that it compares * coordinates instead of "folder names" */ public boolean equals(Point3d q) { return (q.x == x && q.y == y && q.z == z); } }