Liquid { @Override public int hashCode() { int result = 17; result = 31 * result + (int) (amount * 100); result = 31 * result + (int) (temperature * 100); result = 31 * result + color.hashCode(); return result; } Liquid(float amount, float temperature, Color color); final Color getColor(); final float getTemperature(); final float getAmount(); @Override boolean equals(Object other); @Override int hashCode();  }
@Test public void testHashcode() { Liquid liquid1 = new Liquid(1, SimulationConstants.MIN_TEMPERATURE, new Color(1, 1, 1)); Liquid liquid2 = new Liquid(1, SimulationConstants.MIN_TEMPERATURE, new Color(1, 1, 1)); assertEquals(liquid1.hashCode(), liquid2.hashCode()); liquid2 = new Liquid(2, SimulationConstants.MIN_TEMPERATURE, new Color(1, 1, 1)); assertNotEquals(liquid1.hashCode(), liquid2.hashCode()); liquid2 = new Liquid(1, SimulationConstants.MAX_TEMPERATURE, new Color(1, 1, 1)); assertNotEquals(liquid1.hashCode(), liquid2.hashCode()); }