I can't get past the second and the last requirements
package com.codegym.task.task21.task2104;
import java.util.HashSet;
import java.util.Set;
import java.util.Objects;
/*
Equals and HashCode
*/
public class Solution {
private final String first, last;
public Solution(String first, String last) {
this.first = first;
this.last = last;
}
public boolean equals(Solution n) {
if (n == this)
return true;
if(n == null)
return false;
if (!(n instanceof Solution))
return false;
Solution s = (Solution)n;
return Objects.equals(first,s.first) && Objects.equals(last,s.last);
}
public int hashCode() {
// return first.hashCode() + last.hashCode();
if (first == null && last == null)
return 0;
return 31 * first.hashCode() + last.hashCode();
}
public static void main(String[] args) {
Set<Solution> s = new HashSet<>();
s.add(new Solution("Donald", "Duck"));
System.out.println(s.contains(new Solution("Donald", "Duck")));
}
}