Can't pass the testing.

/* Remove all the people born in the summer
Create a dictionary (Map<String, Date>) and add ten entries according to the model «last mane» - «birth date».
    Remove from the map all the people born in the summer.
*/

public class Solution
{
    public static HashMap<String, Date> createMap()
    {
        HashMap<String, Date> map = new HashMap<String, Date>();
        map.put("Stallone", new Date("JUNE 1 1980"));

        //add your code here
        map.put("Stallone2", new Date("JUNE 1 1980"));
        map.put("Stallone3", new Date("JUNE 1 1980"));
        map.put("Stallone4", new Date("JUNE 1 1980"));
        map.put("Stallone5", new Date("JULY 1 1980"));
        map.put("Stallone6", new Date("JUNE 1 1980"));
        map.put("Stallone7", new Date("JUNE 1 1980"));
        map.put("Stallone8", new Date("JUNE 1 1980"));
        map.put("Stallone9", new Date("JANUARY 1 1980"));
        map.put("Stallone10", new Date("AUGUST 1 1980"));
        return map;

    }

    public static void removeAllSummerPeople(HashMap<String, Date> map)
    {
        //add your code here
        Iterator<Map.Entry<String, Date>> iterator = map.entrySet().iterator();
        while(iterator.hasNext())
        {
            Map.Entry<String, Date> pair = iterator.next();
            Date temp = pair.getValue();
            int month = temp.getMonth();
            int day = temp.getDay();
            if (month > 5 && month < 8 )
                map.remove(pair.getKey());
            else if (month == 5 && day >= 21)
                map.remove(pair.getKey());
            else if (month == 8 && day <= 23)
                map.remove(pair.getKey());
        }

    }
}

asked 02 Aug '17, 12:19

genek's gravatar image

genek
173
accept rate: 0%


link

answered 02 Aug '17, 15:15

YourDoom's gravatar image

YourDoom
1811
accept rate: 35%

edited 02 Aug '17, 15:15

So I doesn't need to compare exact dates just months? It should be written in the description.

link

answered 02 Aug '17, 16:26

genek's gravatar image

genek
173
accept rate: 0%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×69
×53
×20

Asked: 02 Aug '17, 12:19

Seen: 853 times

Last updated: 02 Aug '17, 16:26