Добрый день. Подскажите, пожалуйста, что не так? Почему не проходит проверку: "Метод createMap() должен создавать и возвращать словарь HashMap с типом элементов String, String состоящих из 10 записей по принципу «Фамилия» - «Имя».".
Что я упустил? 10 записей - в ключе фамилия, в значении имя. Или я неверно понял задание?
package com.javarush.task.task08.task0815;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
/*
Перепись населения
*/
public class Solution {
public static HashMap<String, String> createMap() {
HashMap<String, String> hmsl = new HashMap<String, String>();
hmsl.put("Иванов", "Иван");
hmsl.put("Петров", "Иван");
hmsl.put("Моисеев", "Иван");
hmsl.put("Иванов", "Пётр");
hmsl.put("Петров", "Геннадий");
hmsl.put("Иванов", "Василий");
hmsl.put("Петров", "Василий");
hmsl.put("Васильев", "Иван");
hmsl.put("Николаев", "Василий");
hmsl.put("Гоголь", "Василий");
return hmsl;
}
public static int getCountTheSameFirstName(HashMap<String, String> map, String name) {
Iterator<Map.Entry<String, String>> it = map.entrySet().iterator();
int cnt = 0;
while (it.hasNext()) {
Map.Entry<String, String> me = it.next();
if (me.getValue() == name) {
cnt++;
}
}
return cnt;
}
public static int getCountTheSameLastName(HashMap<String, String> map, String lastName) {
Iterator<Map.Entry<String, String>> it = map.entrySet().iterator();
int cnt = 0;
while (it.hasNext()) {
Map.Entry<String, String> me = it.next();
if (me.getKey() == lastName) {
cnt++;
}
}
return cnt;
}
public static void main(String[] args) {
}
}