Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.javarush.test.level.lesson.task;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.Iterator;
- import java.util.Map;
- /* Удалить всех людей, родившихся летом
- Создать словарь (Map<String, Date>) и занести в него десять записей по принципу: «фамилия» - «дата рождения».
- Удалить из словаря всех людей, родившихся летом.
- */
- public class Solution {
- public static HashMap<String, Date> createMap() {
- HashMap<String, Date> map = new HashMap<String, Date>();
- map.put("Stallone", new Date("JUNE 1 1980"));
- map.put("Qtallone", new Date("JANUARY 1 1980"));
- map.put("Wtallone", new Date("FEBRUARY 1 1980"));
- map.put("Etallone", new Date("MARCH 1 1980"));
- map.put("Rtallone", new Date("APRIL 1 1980"));
- map.put("Ytallone", new Date("MAY 1 1980"));
- map.put("Utallone", new Date("JUNE 1 1980"));
- map.put("Itallone", new Date("JULY 1 1980"));
- map.put("Otallone", new Date("AUGUST 1 1980"));
- map.put("Ptallone", new Date("SEPTEMBER 1 1980"));
- return map;
- }
- public static void removeAllSummerPeople(HashMap<String, Date> map) {
- Iterator<Map.Entry<String, Date>> iterator = map.entrySet().iterator();
- while (iterator.hasNext()) {
- Map.Entry<String, Date> pair = iterator.next();
- if (pair.getValue().getMonth() > 4 && pair.getValue().getMonth() < 8) {
- iterator.remove();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement