It is not that hard. If you compile it then you'll get this message:
wouter@wouter-laptop:~/temp$ javac TurtleTest.java
TurtleTest.java:39: cannot find symbol
symbol : class Entry
location: class TurtleTest
for (Entry<Turtle, Turtle> t:lh.entrySet())
Saying that it cannot find that class. So just import it
But then it still does not want you want it to do because the hashCode method has not been implemented (A Map uses hashCode and equals to determine if objects are equal, not the comparable interface).
So implement the hashCode and equals methods properly. Total code:
And then the output is 3 which is what we wanted/expected.
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.