What do you think?
package com.codegym.task.task08.task0815;
import java.util.*;
import static java.lang.System.out;
/*
Census
Create a Map<String, String> and add ten entries that represent (last name, first name) pairs.
Check how many people have the same first name or last name.
*/
public class Solution {
public static HashMap<String, String> createMap() {
HashMap<String, String> phoneBook = new HashMap<>();
Random rnd = new Random(20);
ArrayList<String> lastNames = new ArrayList<String>(Arrays.asList(("Roberts Gonzalez Foster Wallace").split(" ")));
while(phoneBook.size() < 10) {
phoneBook.put(Integer.toString(rnd.nextInt()), lastNames.get(rnd.nextInt(lastNames.size())));
}
return phoneBook;
}
public static int getSameFirstNameCount(HashMap<String, String> map, String name) {
int count = 0;
for(Map.Entry<String, String> entry: map.entrySet()) {
if(entry.getKey().equals(name)) { count++; }
}
return count;
}
public static int getSameLastNameCount(HashMap<String, String> map, String lastName) {
int count = 0;
for(Map.Entry<String, String> entry: map.entrySet()) {
if(entry.getValue().equals(lastName)) { count++; }
}
return count;
}
public static void main(String[] args) {
/*
HashMap<String, String> hey = createMap();
for(Map.Entry<String, String> entry: hey.entrySet()) {
out.println(entry.getKey()+" "+entry.getValue());
}
out.println(getSameFirstNameCount(hey, "-37565341")+" "+getSameLastNameCount(hey, "Gonzalez"));
*/
}
}