
//Step 1; Create a class called Coordinate which 
// encapsulates the idea of a 3D coordinates (x, y, z).
public class Coordinate {

	//Step 2: Make an array of 3 doubles to store the x, y, and z values.
	// coord[0] is the x-coordinate
	// coord[1] is the y-coordinate
	// coord[2] is the z-coordinate
	private double[] coord;
	
	
	//Step 3: Write a no-parameter constructor which sets x, y, and z to 0.
	public Coordinate() {
		coord = new double[3]; 
		//default values are 0
		
		// this(0,0,0); would work after the other constructor was created
	}
	
	//Step 4: Write a constructor with x, y, and z as parameters, 
	// to create and fill the array.
	public Coordinate(double x, double y, double z) {
		coord = new double[3];
		coord[0] = x;
		coord[1] = y;
		coord[2] = z;
	}
	
	//Step 5:  Write getX, getY, and getZ methods to get the 
	//  x, y, and z values respectively.
	public double getX() {
		return coord[0];
	}

	public double getY() {
		return coord[1];
	}

	public double getZ() {
		return coord[2];
	}

	
	
	//Step 6: Write setX, setY, and setZ methods to change the 
	//  x, y, and z values respectively.
	public void setX(double value) {
		coord[0] = value;
	}
	
	public void setY(double value) {
		coord[1] = value;
	}
	
	public void setZ(double value) {
		coord[2] = value;
	}
	
	//Step 7: Write a setValue method with x, y, and z as parameters.
	public void setValue(double x, double y, double z) {
		coord[0] = x;
		coord[1] = y;
		coord[2] = z;
	}
	
	//Step 8:  Write a distance method which takes another Coordinate object 
	//  as a parameter and returns the distance between the object and the 
	//  parameter. The distance between two coordinates is the square root 
	//  of the sum of the square-differences of the 3 values.
	public double distance(Coordinate point2) {
		double result = 0;
		
		//loop is not required, but we can use one
		for(int i = 0; i < this.coord.length; i++) {
			//difference
			double diff = this.coord[i] - point2.coord[i];
			//square it and add it to the result
			result += diff*diff;
		}
		
		//return the square root of the sum
		return Math.sqrt(result);
	}
	
	//Step 9: Write a toString method to print the x, y, and z coordinates. 
	// Look at the test program for the format.
	public String toString() {
		return String.format("[ %.2f, %.2f, %.2f ]", coord[0], coord[1], coord[2]);
	}
	
}
