Explorar el Código

Add hashCode method to starter solution

Jack Mustacato hace 8 años
padre
commit
40c165104c
Se han modificado 1 ficheros con 10 adiciones y 0 borrados
  1. 10
    0
      exercises/rational-numbers/src/main/java/Rational.java

+ 10
- 0
exercises/rational-numbers/src/main/java/Rational.java Ver fichero

@@ -27,4 +27,14 @@ class Rational {
27 27
         return this.getNumerator() == other.getNumerator()
28 28
             && this.getDenominator() == other.getDenominator();
29 29
     }
30
+
31
+    @Override
32
+    public int hashCode() {
33
+        int prime = 31;
34
+        int result = 1;
35
+        result = prime * result + this.getNumerator();
36
+        result = prime * result + this.getDenominator();
37
+
38
+        return result;
39
+    }
30 40
 }