Esperanto:
Mi havas problemon. La ciklo el linio 40 al linio 49 sxaltas en la linio 46 unufoje, kaj ne ne plu. La programo forigas nur unu linion el "map" strukturo ne tri.
Mi ne komprenas kial.
English:
I have a problem. The cycle from line 40 to 49 jumps into the line 46 only once. The program removes only inle line from the map structure and not three.
I do not understand why.
package com.codegym.task.task08.task0816;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Month;
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("JUNE 1 1980"));
//write your code here
map.put("Stallone1", df.parse("JULY 1 1980"));
map.put("Stallone2", df.parse("AUGUST 1 1980"));
map.put("Stallone3", df.parse("SEPTEMBER 1 1980"));
map.put("Stallone4", df.parse("OCTOBER 1 1980"));
map.put("Stallone5", df.parse("NOVEMBER 1 1980"));
map.put("Stallone6", df.parse("JANUARY 1 1980"));
map.put("Stallone7", df.parse("FEBRUARY 1 1980"));
map.put("Stallone8", df.parse("MARCH 1 1980"));
map.put("Stallone9", df.parse("APRIL 1 1980"));
return map;
}
public static void removeAllSummerPeople(HashMap<String, Date> map) throws ParseException {
//write your code here
int nyar;
int i = 0;
Calendar ido = Calendar.getInstance();
for (HashMap.Entry<String, Date> pair : map.entrySet()) {
i = i + 1;
Date date = pair.getValue();
ido.setTime(date);
nyar = ido.get(Calendar.MONTH);
if ((nyar == 5) || (nyar == 6) || (nyar == 7)) {
map.remove(pair.getValue());
map.remove(pair.getKey());
}
}
}
public static void main(String[] args) throws Exception {
HashMap<String, Date> map = createMap();
removeAllSummerPeople(map);
for (HashMap.Entry pair : map.entrySet()) {
System.out.println(pair.getKey());
System.out.println(pair.getValue());
}
}
}