People and other citizens of the universe quite often try to find their relatives. Let's take a step towards a program that can search for people. In this task, we need to create a dictionary (Map), add ten (last name, first name) entries, and then check how many people have the same first name or last name.
Census
- 10
Locked
Comments (44)
- Popular
- New
- Old
You must be signed in to leave a comment
RodYokoo
17 April 2022, 17:55
Hint: it's impossible to set repeated keys in hashmap without MuliMap or a list as value.
0
Dinesh Full Stack Developer at Byndr Technologies
15 December 2021, 05:14
Please see in the question description : Create a Map<String, String> and add ten entries that represent (last name, first name) pairs, it tells that last name is key and first name is value. And we have to iterate using keySet(), values() methods accordingly
0
Michael
12 June 2021, 12:00
The corresponding section "List of all collections" (8/2) is much too short and too trivial for the complexity of the topic and this challenge is over the top.
0
Khongpak Phupkdee
1 May 2021, 02:27
First
They import 2 class are
import java.util.HashMap;
import java.util.HashSet;
But I don't know the purpose of this practice is to use only 2 class and solve the practice's problems or don't care I can import more than them because It has a lot of ways to solve. I need to know the truly of purpose
0
Roman
5 May 2021, 05:43
The imports are just for help, you can use other imports to solve the task.
+1
ImDevin
29 April 2021, 13:58
Ditto with all the previous comments. Very poorly written instruction, almost misleading (done on purpose? If so, why?). Pretty silly exercise to compare the list to itself (lastName, name). Maybe the point was to make us aware of the need to test them separately, and to make us practice using keySet iterator and value iterator? Don't know, but thx to everyone who wrote comments. Without them, would've wasted a lot of time, instead, after reading/thinking for 30 minutes, wrote the logic in 5 minutes and passed. Happy coding! :)
+1
Anitamalina
18 December 2020, 09:46
this task needs some better description. It's really misleading in the way it asks you to "Check how many people have the same first name or last name". But you can't add the same lastName (key) to the HashMap, since the key has to be unique! It's sooo confusing.
+1
Devonte A
7 February 2021, 13:06
Yep but think about it that means the key will always return 1 or 0..So your job is just to find the count and ignore the rest.
0
Nickolas Johnson
30 November 2020, 16:28
Level of code difficulty for this one: about 2/5
Level of directions readability: 0/5
This one tries to trick you for sure. Anyone reading this should just recognize that given the use of a HashMap and that said hashmap will have Last Name as the KEY, it is not possible to have more than 1 repeat since you cannot repeat keys. I spent half an hour reading comments over and over until someone else finally pointed that out and i started actually coding.
It's also worth mentioning that if you "map.put" the same lastname more than once, the hashmap will treat that as a value change and not add another element. So, if you're failing on the third one take a look at your actual hashmap to see if it's actually 10.
+1
Ron R
8 December 2020, 17:21
Agreed. Spent more time reading comments than I spent with my code. Before I submitted my solution, I was trying to figure out why the conditions would say write a method to count duplicate last names, last names being the "key", knowing keys are unique.
0
Vitalina
15 October 2020, 11:14
I hate this task. And that is because keys and values:(
+1
ziv fisher
26 September 2020, 20:12
The 3rd condition is wrongly worded:
״Check how many people have the same first name or last name.״ ----- THIS IS MISLEADING!
For other students, pay attention to the argument passes in the "getSameFirstNameCount"+"getSameLastNameCount" methods.
More specifically: (HashMap<String, String> map, String lastName)
And more specifically: (HashMap<String, String> map, String name)
What they basically wanted is you to compare the String lastName(in the getSameLastNameCount method) that is passes as an argument in the getSameLastNameCount method(for example) to all of the keys(which are Strings at this example) at the HashMap and count how many Strings(keys) is the same String as the argument(String lastName).
0
Karas Java Developer
22 September 2020, 00:32
Okay, this exercise completelly broke my record of 1 to 3 tries.
I might be the one to give away the clue but seeing the different number of request and petitions to help, this needs to be addressed.
The sequence of the map:
LAST NAME will be the KEY.
FIRST NAME will be the VALUE.
Compare them to the passed parameter accordingly.
+1