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 (28)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Anonymous #10775689
Level 14 , United Kingdom
1 August, 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!
Level 41 , Olympus Mons, Mars
25 May, 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, 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, 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 , 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 9 , Dresden, Germany
12 June, 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.
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.