Hello fellow future programmers.
I'm stuck on the last requirement. I have been reading and it has helped a lot (my program finally compiles). However I can't delete the people from summer months. Could someone please point me in the right directions or tell me where i lost my way?
Thanks.
package com.codegym.task.task08.task0816;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Locale;
import java.util.Calendar;
import java.util.Iterator;
import java.util.Map;
/*
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("JUNE 1 1980"));
map.put("Revees", df.parse("MAY 5 1982"));
map.put("Jolie", df.parse("FEBRUARY 1 1990"));
map.put("Roberts", df.parse("MARCH 2 1983"));
map.put("VanDame", df.parse("AUGUST 2 1999"));
map.put("Pitt", df.parse("JANUARY 5 1997"));
map.put("Cloonie", df.parse("DECEMBER 5 1995"));
map.put("DelToro", df.parse("OCTOBER 9 1993"));
map.put("Denzel", df.parse("NOVEMBER 8 1990"));
map.put("Trucks", df.parse("MARCH 1 1988"));
return map;//write your code here
}
public static void removeAllSummerPeople(HashMap<String, Date> map) {
Calendar c = Calendar.getInstance();
Iterator<Map.Entry<String, Date>> iter = map.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry<String, Date> entry = iter.next();
if(c.get(Calendar.MONTH) == 5 || c.get(Calendar.MONTH) == 6|| c.get(Calendar.MONTH) == 7){
iter.remove();
}
}//write your code here
}
public static void main(String[] args) throws Exception{
HashMap<String, Date> map2 = new HashMap<String, Date>();
map2 = createMap();
removeAllSummerPeople(map2);
}
}