Emma Richards is the supervising teacher of grade 7B at some Terran school. The details aren't important. What is important is that she gives gifts to the students on their birthdays. But not everyone is lucky: Summer birthdays are skipped due to the summer break. Let's write a program for Emma: create a dictionary with names and birth dates, and then remove anybody born in the summer.
Kind Emma and the summer holidays
- 10
Locked
Comments (31)
- Popular
- New
- Old
You must be signed in to leave a comment
Shamil
11 July 2022, 22:34
I used Iterator and Date.getMonth() to check.
0
RodYokoo
17 April 2022, 19:46
This is not the hardest, but I took more time than I realy want to because I didn't read the hint
LOL
0
Anonymous #10775689
1 August 2021, 07:45
Could someone please help me understand how this line in the provided solution...
returns the date? Looking at the input data, eg...
isn't the name the key, and the date the value?
Thanks! 0
Gellert Varga
21 January 2022, 16:23
Yes, name is the key, Date is the value, and
the hsmap.get(key) method does not return any key, but returns the value defined by the given key.
0
Naughtless
25 May 2021, 03:45
So to the people having problems with the "Hard" tasks, you need to either:
1. Get creative with your pre-existing knowledge.
2. Do research.
I got creative.
I printed out the date as String and splitted it. If the month is "June", "July", or "August", then you iterator.remove();
Good luck!
+2
Khongpak Phupkdee
2 May 2021, 09:47
It was something very dizzy, but I passed.
Take 2 days for this exercise.
I would like to recommend If you want to change the month format from JAN,JUNE,JULY,..,DEC to number you can use
it will be change from DATE TYPE to INT 0
ImDevin
29 April 2021, 22:01
Since Date class is deprecated, I looked up a lot about Calendar class, which is the replacement for the Date class. Took a while to figure out the answer. Can solve by doing either for-each loop or using the iterator, but for both, you must set the calendar(calendar.setTime) with the value from the key-value set; otherwise, it won't pass. Glad people asked good questions and thankful for those who answered questions. Thanks for sharing. Happy coding! :)
+1
Samuel MichaelExpert
4 January 2021, 20:51
A useful tip to bypass Concurrent Modification Exception.
Create a duplicate of the Hashmap and use that in the for-each loop.
At the end of the loop. Make desired modifications(insert, remove) to the original copy, that way you are not iterating through and modifying the map at the same time.
0
Joe M
29 December 2020, 21:09
I find the Alex Lee videos on youtube helpful for some of these topics, like HashSet, HashMap etc.https://www.youtube.com/watch?v=PeFyhRr42ac
+2
kar-fai chow
22 November 2020, 14:19
I'm seeing a pattern here:
If it is "Hard", they don't bother teaching anything or provide any example, you just go ahead and google away
None of the past lessons are going to help you here
+8
Michael
12 June 2021, 12:09
You read my thoughts! Doing things this way is not very encouraging nor is it productive!
+1
Karas Java Developer
26 September 2020, 20:28
Okay, I have to say two things about this exercise.
First, it will not show if there is an error on the background and will show it as running and work but when verifying it will fail. As seen in different comments and help request the last requirement is failing, because you can not REMOVE from and iterating map using a for loop, this error is a common mistake in newbies like me.
Second thing, to solve it, yes you can use the .getMonth() on the date, but first create a copy of the map and iterate through with a for loop then REMOVE from the original parameter map, then it will work. Also you could use an iterator, I did not try that but might work.
Somehow the errors are not been shown in the console, unfortunatelly sometimes that is what tells you where is the mistake. Hope this helps.
+5