Kind Emma and the summer holidays

  • 10
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 (24)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Khong. Ph.
Level 8, Chiangrai, Thailand
2 May, 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
ImDevin
Level 9, Old Town, United States
29 April, 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, 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 11, East Coast, 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.https://www.youtube.com/watch?v=PeFyhRr42ac
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
Karas
Level 19, Tampa, United States
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.
George
Level 15, United Kingdom
14 September 2020, 22:53
had to use the deprecated Date.getMonth(). Not sure how else this could work unless i split the date string values (" " as separator), and pick the second one which would be the month. That would be cause even though the formatter is "MMMM d yyyy" that's only for entry. In the map they're all in Date format. If anyone had a better idea please let me know.
Baurzhan Konurbayev
Level 40, United States
27 July 2020, 04:03
I used this to calculate month
int month = cal.get(Calendar.MONTH) + 2;
Why did I have to use +2 ? While it worked correctly on my laptop with just +1. I am using openjdk 14.0.2 on my laptop.
Petros
Level 23, Columbia, United States
24 July 2020, 22:48
That was brutal. And I still don't know what I did.
Timboo
Level 16, Shantou, China
1 July 2020, 11:14
What's the problem about my code? Can't match the last requirement.