Color { @Override public int hashCode() { int result = 17; result = 31 * result + (int) Math.round(cyan * 10000); result = 31 * result + (int) Math.round(magenta * 10000); result = 31 * result + (int) Math.round(yellow * 10000); return result; } Color(double cyan, double magenta, double yellow);  Color(int rgb); final double getCyan(); final double getMagenta(); final double getYellow(); final double getR(); final double getG(); final double getB(); int getRGB(); @Override boolean equals(Object other); @Override int hashCode();  }
@Test public void testHashcode() { Color color1 = new Color(0.5, 0.5, 0.5); Color color2 = new Color(0.5, 0.5, 0.5); assertEquals(color1.hashCode(), color2.hashCode()); color2 = new Color(0.5, 0.5, 0.6); assertNotEquals(color1.hashCode(), color2.hashCode()); }