Mine seems to be working to remove all entries with dates of June, July, or August, but validator says:
Be sure that the removeAllSummerPeople() method removes people born in the summer from the map.
package com.codegym.task.task08.task0816;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
/*
Kind Emma and the summer holidays
*/
public class Solution {
public static HashMap<String, Date> createMap() throws ParseException {
DateFormat df = new SimpleDateFormat("MMMMM d yyyy", Locale.ENGLISH);
HashMap<String, Date> map = new HashMap<String, Date>();
map.put("Stallone", df.parse("July 1 1980"));
map.put("Roberts", df.parse("July 2 1980"));
map.put("Rogers", df.parse("July 1 1980"));
map.put("Barstow", df.parse("August 1 1980"));
map.put("Kroger", df.parse("September 1 1980"));
map.put("Lowes", df.parse("October 1 1980")); //6
map.put("Buick", df.parse("November 1 1980"));
map.put("Toyota", df.parse("December 1 1980"));
map.put("Grainger", df.parse("January 1 1980"));
map.put("Cathy", df.parse("February 1 1980"));
//write your code here
return map;
}
public static void removeAllSummerPeople(HashMap<String, Date> map) {
//write your code here
Iterator<Map.Entry<String, Date>> iterator = map.entrySet().iterator();
//System.out.println("here");
while (iterator.hasNext()){
Map.Entry<String, Date> pair = iterator.next();
//iterator.next();
//System.out.println(pair.getKey() + ":" + pair.getValue());
Date thisDate = pair.getValue();
//System.out.println("This one's date's month is: " + thisDate.getMonth());
if(thisDate.getMonth() > 5 && thisDate.getMonth()<9){
//System.out.println("this key needs to be removed");
iterator.remove();
}
}
}
public static void main(String[] args) throws ParseException {
HashMap<String, Date> output = Solution.createMap();
//System.out.println("before " + output);
Solution.removeAllSummerPeople(output);
//System.out.println(output);
}
}