Ich habe das Programm getestet und alle im Sommer geborenen werden aus der Map entfernt. Ich verstehe nicht, warum der letzte Punkt nicht anerkannt wird. Hat einer von euch einen Tipp?
package de.codegym.task.task08.task0816;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
/*
Die liebe Emma und die Sommerferien
*/
public class Solution {
public static HashMap<String, Date> mapErstellen() throws ParseException {
DateFormat df = new SimpleDateFormat("MMMMM d yyyy", Locale.ENGLISH);
HashMap<String, Date> map = new HashMap<String, Date>();
map.put("Stallone", df.parse("JANUARY 1 1980"));
map.put("Presley", df.parse("JUNE 5 1986"));
map.put("Gandhi", df.parse("APRIL 21 1990"));
map.put("Einstein", df.parse("MAY 1 2005"));
map.put("Schwarzenegger", df.parse("JULY 1 1980"));
map.put("Monroe", df.parse("AUGUST 31 1980"));
map.put("Hawking", df.parse("DECEMBER 24 1980"));
map.put("Norris", df.parse("JUNE 30 1980"));
map.put("Schmidt", df.parse("NOVEMBER 1 1980"));
map.put("Kohl", df.parse("JUNE 12 1980"));
//schreib hier deinen Code
return map;
}
public static void alleSommergeburtstagskinderEntfernen(HashMap<String, Date> map) throws ParseException {
//schreib hier deinen Code
DateFormat ndf = new SimpleDateFormat("MMMMM d", Locale.ENGLISH);
Date date1;
Date date2 = ndf.parse("JUNE 1");
Date date3 = ndf.parse("AUGUST 31");
Iterator it = map.entrySet().iterator();
while (it.hasNext()){
Map.Entry item = (Map.Entry) it.next();
date1 = ndf.parse(ndf.format(item.getValue()));
if (date1.compareTo(date2) > 0 && date1.compareTo(date3) < 0)
it.remove();
}
}
public static void main(String[] args) throws ParseException {
}
}