Advertisement
romancha

task_816

Aug 2nd, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.94 KB | None | 0 0
  1. import java.text.ParseException;
  2. import java.text.SimpleDateFormat;
  3. import java.util.*;
  4.  
  5. /*
  6. Добрая Зинаида и летние каникулы
  7. */
  8.  
  9. public class test {
  10.     public static HashMap<String, Date> createMap() throws Exception {
  11.  
  12.         HashMap<String, Date> map = new HashMap<String, Date>();
  13.         SimpleDateFormat format = new SimpleDateFormat("MMMM dd yyyy", Locale.ENGLISH);
  14.         map.put("Stallone", format.parse("JUNE 01 1980"));        //напишите тут ваш код
  15.         map.put("S1", format.parse("JANUARY 01 1980"));
  16.         map.put("S2", format.parse("MARCH 05  1980"));
  17.         map.put("S3", format.parse("APRIL 10 1980"));
  18.         map.put("S4", format.parse("JULY 11 1980"));
  19.         map.put("S5", format.parse("JUNE 07 1980"));
  20.         map.put("S6", format.parse("SEPTEMBER 11 1980"));
  21.         map.put("S7", format.parse("MAY 17 1980"));
  22.         map.put("S8", format.parse("AUGUST 11 1980"));
  23.         map.put("S9", format.parse("MAY 01 1980"));
  24.  
  25.         return map;
  26.     }
  27.  
  28.     public static void removeAllSummerPeople(HashMap<String, Date> map) {
  29.         //напишите тут ваш код
  30.         ArrayList<String> delete = new ArrayList<>();
  31.         for(Map.Entry<String,Date> pair:map.entrySet()){
  32.             if(pair.getValue().getMonth() > 4 && pair.getValue().getMonth() < 8){
  33.                 delete.add(pair.getKey());
  34.             }
  35.         }
  36.  
  37.         for(String object : delete) {
  38.             map.remove(object);
  39.         }
  40.     }
  41.  
  42.     public static void main(String[] args) throws Exception{
  43.         //Это для тестов программы и проверки ее работы, после удалить все из метода мэйн
  44.         HashMap<String, Date> map = createMap();
  45.         removeAllSummerPeople(map);
  46.  
  47.         for(Map.Entry<String,Date> pair:map.entrySet()){
  48.             System.out.println(pair.getKey() + " " + pair.getValue());
  49.         }
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement