// import java.security.acl.LastOwnerException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
/*
Перепись населения
*/
public class Solution {
public static HashMap<String, String> createMap() {
HashMap <String, String> map = new HashMap <> ( );
map.hashCode ();
map.put ("Ivanov","Vasya");
map.put ("Vasilev","Vasya");
map.put ("Konstantinov","Vasya");
map.put ("IvanovVasilev", "Ivan");
map.put ("IvanovKonstantinov", "Kolya");
map.put ("Kolkin", "Kolya");
map.put ("IvanovTemkin", "Tema");
map.put ("IvanovIvanov", "Maks");
map.put ("Temkin", "Tema");
map.put ("IvanovIvanovIvanov", "Petya");
for (String key: map.keySet ()) {
// System.out.println (key);
}
return map;
}
public static int getCountTheSameFirstName(HashMap<String, String> map, String name) {
int count = 0;
for (Map.Entry <String,String> korzina: map.entrySet ()){
if (korzina.getValue ().equals ( name )) count++;
// System.out.println(name + " - " + count);
}
// System.out.println ("How many name: " + name + " " + count);
return count;
}
public static int getCountTheSameLastName(HashMap<String, String> map, String lastName) {
int yes = map.containsKey ( lastName ) ? 1:0;
// System.out.println ("Есть ли такая фамилия: " + yes);
return yes;
}
public static void main(String[] args) {
HashMap <String, String> map = createMap ();
getCountTheSameFirstName (map,"Maks");
getCountTheSameLastName ( map, "Ivanov3" );
}
}
package com.javarush.task.task08.task0815;
import java.util.HashMap;
import java.util.HashSet;
/*
Перепись населения
*/
public class Solution {
public static HashMap<String, String> createMap() {
HashMap<String, String> Map = new HashMap<String, String>();
Map.put("kekSurname3", "kekName1");
Map.put("kekSurname2", "kekName3");
Map.put("kekSurnamfe3", "kekName3");
Map.put("kekSurdname", "kekName");
Map.put("kekSusrname5", "kekName5");
Map.put("kekSuvrname", "kekName");
Map.put("kekSucrname", "kekName");
Map.put("kekSudrname8", "kekName8");
Map.put("keksSurname", "kekName");
Map.put("kehkSurname", "kekName");
return Map;
}
public static int getCountTheSameFirstName(HashMap<String, String> map, String name) {
int i = 0;
for(String n : map.values())
if(n.equals(name))
i++;
return i;
}
public static int getCountTheSameLastName(HashMap<String, String> map, String lastName) {
int i = 0;
for(String n : map.keySet())
if(n.equals(lastName))
i++;
return i;
}
public static void main(String[] args) {
}
}