Loading...
Loading...
Loading...
A phone merges duplicate contacts. A contact has a name and an email; a - in the input means the contact has no email, which you store as null. Two contacts are equal when both the name and the email match, and two missing emails count as matching. Write equals() and hashCode() with Objects.equals and Objects.hash, then print EQUAL or NOT EQUAL for each pair.
name1 email1 name2 email2, where an email may be -.EQUAL or NOT EQUAL for each pair.Example
Input
3 Rohan - Rohan - Rohan - Rohan rohan@mail.com Diya diya@mail.com Diya diya@mail.com
Output
EQUAL NOT EQUAL EQUAL
Two missing emails match; a missing email and a real one do not.
Try the problem first. Open one hint at a time.
email.equals(other.email) crashes when email is null.
Objects.equals(a, b) is true for two nulls, false for one null, else a.equals(b).
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor