Kind Emma and the summer holidays

  • 10
  • Locked
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.
You can't complete this task, because you're not signed in.
Comments (31)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Level 19 , Kyiv, Ukraine
11 July 2022, 22:34
I used Iterator and Date.getMonth() to check.
Level 10 , Brazil
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
Anonymous #10775689
Level 14 , United Kingdom
1 August 2021, 07:45
Could someone please help me understand how this line in the provided solution...
Date date = copy.get(key);
returns the date? Looking at the input data, eg...
map.put("Stallone", df.parse("MAY 1 2012"));
isn't the name the key, and the date the value? Thanks!
Gellert Varga
Level 23 , Szekesfehervar, Hungary
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.
Level 41 , Olympus Mons, Mars
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!
Khongpak Phupkdee
Level 15 , Chiangrai, Thailand
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
int a = pair.getValue().getMonth();
it will be change from DATE TYPE to INT
Level 15 , Old Town, United States
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! :)
Samuel Michael
Level 16 , Stafford, United States
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.
Joe M
Level 47 , Owings Mills, United States
29 December 2020, 21:09
I find the Alex Lee videos on youtube helpful for some of these topics, like HashSet, HashMap etc.
kar-fai chow
Level 8 , Hong Kong, Hong Kong
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
Level 10 , Dresden, Germany
12 June 2021, 12:09
You read my thoughts! Doing things this way is not very encouraging nor is it productive!
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.