Advertisement
jaVer404

level08.lesson08.task03

Apr 18th, 2015
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.76 KB | None | 0 0
  1. package com.javarush.test.level08.lesson08.task03;
  2.  
  3. import java.util.HashMap;
  4. import java.util.Map;
  5.  
  6. /* Одинаковые имя и фамилия
  7. Создать словарь (Map<String, String>) занести в него десять записей по принципу «Фамилия» - «Имя».
  8. Проверить сколько людей имеют совпадающие с заданным имя или фамилию.
  9. */
  10.  
  11. public class Solution
  12. {
  13.     public static HashMap<String, String> createMap()
  14.     {
  15.         //Напишите тут ваш код
  16.         HashMap<String, String> myMap = new HashMap<String, String>();
  17.         myMap.put("Putin1", "Huylo");
  18.         myMap.put("Putin2", "Huylo");
  19.         myMap.put("Putin3", "Huylo");
  20.         myMap.put("Putin4", "Huylo");
  21.         myMap.put("Putin5", "Huylo");
  22.         myMap.put("Putin6", "Huylo");
  23.         myMap.put("Putin7", "Huylo");
  24.         myMap.put("Putin8", "Huylo");
  25.         myMap.put("Putin9", "Huylo");
  26.         myMap.put("Putin10", "Huylo");
  27.         return myMap;
  28.     }
  29.  
  30.     public static int getCountTheSameFirstName(HashMap<String, String> map, String name)
  31.     {
  32.         //Напишите тут ваш код
  33.         int i1 = 0;
  34.         for (Map.Entry<String,String> pair : map.entrySet()) {
  35.             if (pair.getValue().equals(name)) {
  36.                 i1++;
  37.             }
  38.     }
  39.         return i1;
  40.     }
  41.  
  42.     public static int getCountTheSameLastName(HashMap<String, String> map, String familiya)
  43.     {
  44.         //Напишите тут ваш код
  45.         int i2 = 0;
  46.         for (Map.Entry<String,String> pair : map.entrySet()) {
  47.             if (pair.getKey().equals(familiya)) {
  48.                 i2++;
  49.             }
  50.         }
  51.         return i2;
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement