class Worm implements Comparable<Worm> {
	private int length;
	private String name;
	private float weight;

	public Worm(String name, int length, float weight) {
		this.name = name;
		this.length = length;
		this.weight = weight;
	}

	@Override
	public String toString() {
		return "Length: " + length + " Name:" + name + " Weight: " + weight;
	}
		
	@Override
	public boolean equals(Object obj) {
		if(!(obj instanceof Worm)) { return false; }
		Worm w = (Worm) obj;
		return (this.length == w.length && 
			this.name.equals(w.name) && 
			Math.abs(this.weight - w.weight) < 0.000001);
	} 

	@Override
	public int hashCode() {
		int result = 13;
		result += 31 * result + this.length;
		result += 31 * result + this.name.hashCode();
		result += 31 * result + Float.floatToIntBits(this.weight);
		return result;
	}
		
	public int compareTo(Worm w) {
		if(this.length - w.length == 0) {
			return Float.compare(this.weight,w.weight);
		}
		else {
			return this.length - w.length;
		}
	}
}
