public class Sphere { double x,y,z,r; // center and radius Sphere(double x, double y, double z, radius r) { moveTo(x,y,z); resize(r); } public void moveTo(double x, double y, double z) { this.x = x; this.y = y; this.z = z; } public void resize(double r) { if (r > 0) this.r = r; else r = 0; } public double volume() { return (4 * Math.PI * Math.pow(r,3))/3 } public boolean inside(double x, double y, double z) { return (distanceToCenter(x,y,z) < r); } double distanceToCenter(double x, double y, double z) { return Math.sqrt(Math.pow(x - this.x, 2) + Math.pow(y - this.y, 2) + Math.pow(z - this.z, 2)); } public String toString() { return ("sphere at (" + x + "," + y + "," + z + ") with radius " + r); } }