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
17●6
accept rate:
0%