Tsuki11

Untitled

Jun 20th, 2020
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. Problem 7. *Equality Logic
  2. Create a class Person holding name and age. A person with the same name and age should be considered the same, override any methods needed to enforce this logic. Your class should work with both standard and hashed collections. Create a TreeSet and a HashSet of type Person.
  3. Input
  4. On the first line of input you will receive a number N. On each of the next N lines you will receive information about people in the format "<name> <age>". Add the people from the input into both sets (both sets should hold all the people passed in from the input).
  5. Output
  6. The output should consist of exactly 2 lines. On the first you should print the size of the TreeSet and on the second - the size of the HashSet.
  7. Constraints
  8. • A person’s name will be a string that contains only alphanumerical characters with a length between [1…50] symbols.
  9. • A person’s age will be a positive integer between [1…100].
  10. • The number of people N will be a positive integer between [0…100].
  11. Examples
  12. Input Output
  13. 4
  14. Pesho 20
  15. Peshp 20
  16. Joro 15
  17. Pesho 21 4
  18. 4
  19. 7
  20. Ivan 17
  21. ivan 17
  22. Stoqn 25
  23. Ivan 18
  24. Ivan 17
  25. Stopn 25
  26. Stoqn 25 5
  27. 5
  28. Hint
  29. You should override both the equals and hashCode methods. You can check online for an implementation of hashCode - it doesn’t have to be perfect, but it should be good enough to produce the same hash code for objects with the same name and age, and different enough hash codes for objects with different name and/or age.
Add Comment
Please, Sign In to add comment