import java.util.ArrayList;
import java.util.Collections;

public class Coordinate implements Comparable<Coordinate> {
	private double _x;
	private double _y;
	private double _z;
	
	public Coordinate(double x, double y, double z) {
		_x = x;
		_y = y;
		_z = z;
	}

	public double getX() { return _x; }
	public double getY() { return _y; }
	public double getZ() { return _z; }
	
	public int compareTo(Coordinate other) {
		double distanceOfSelf = Math.sqrt(this.getX()*this.getX()
									      + this.getY()*this.getY()
									      + this.getZ()*this.getZ()); 
										 
		double distanceOfOther = Math.sqrt(other.getX()*other.getX()
									       + other.getY()*other.getY()
									       + other.getZ()*other.getZ()); 
										  
		if (distanceOfSelf < distanceOfOther) {
			return -1;
		}
		else if (distanceOfSelf > distanceOfOther) {
			return 1;
		}
		else {
			// Condition here: distanceOfSelf == distanceOfOther
			return 0;
		}
	}
	
	
	// Here is a tester for you to use. Uncomment it after you have finished making this class sortable
	public static void main(String[] args) {
		ArrayList<Coordinate> coords = new ArrayList<Coordinate>();
		coords.add( new Coordinate(0,1,1) );
		coords.add( new Coordinate(2,3,5) );
		coords.add( new Coordinate(1,4,0) );
		coords.add( new Coordinate(1,1,1) );
		coords.add( new Coordinate(1,1,0) );
		coords.add( new Coordinate(3,2,5) );
		
		Collections.sort(coords);
		
		for (int i=0; i<coords.size(); i++) {
			Coordinate current = coords.get(i);
			double distance = Math.sqrt(current.getX()*current.getX()
									    + current.getY()*current.getY()
									    + current.getZ()*current.getZ());
									   
			System.out.println("Rank " + i + ": (" + current.getX() + ", " 
			                   + current.getY() + ", " + current.getZ() 
							   + ") with distance " + distance);
		}
	}
}
