Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Problem 7. *Equality Logic
- 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.
- Input
- 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).
- Output
- 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.
- Constraints
- • A person’s name will be a string that contains only alphanumerical characters with a length between [1…50] symbols.
- • A person’s age will be a positive integer between [1…100].
- • The number of people N will be a positive integer between [0…100].
- Examples
- Input Output
- 4
- Pesho 20
- Peshp 20
- Joro 15
- Pesho 21 4
- 4
- 7
- Ivan 17
- ivan 17
- Stoqn 25
- Ivan 18
- Ivan 17
- Stopn 25
- Stoqn 25 5
- 5
- Hint
- 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