10: Hashcodes
Submit this homework using Gradescope. You can type up your answers, or write legibly and scan them. Do not attempt to submit a paper copy in class, as it will not be accepted.
Suppose you have a Banana class with the following instance variables:
private int expiredDate;
private int count;
private List<String> varieties;
And a Mango class with the following instance variables:
private String name;
private String color;
private Mango mango; // mango-ception
A. (1 points) Write a valid equals method for the Banana class.
B. (1 points) Write a valid equals method for the Mango class.
C. (1 points) Write a valid hashCode method for the Banana class.
D. (1 points) Write a valid hashCode method for the Mango class.
Notes:
- Each of the instance variables must be considered when considering equality.
- For full credit, your answer must both obey the
hashCodecontract as well as attempt to return distinct integers for distinct objects. No “return 1;” shenanigans! - Finally, no one actually writes these things themselves. Feel free to use your IDE for help!