package com.codegym.task.task08.task0815;
import java.util.*;
import static java.lang.System.out;
/*
Census
*/
public class Solution {
public static HashMap<String, String> createMap() {
HashMap<String, String> phoneBook = new HashMap<String, String>();
Random rnd = new Random(20);
ArrayList<String> lastNames = new ArrayList<String>(Arrays.asList(("Robert's Gonzlez Foster Wallance").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.getValue().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.getKey().equals(lastName)){
count++;
}
}
return count;
}
public static void main(String[] args) {
}
}
Executed Pogram
Resolved
Comments
- Popular
- New
- Old
You must be signed in to leave a comment
This page doesn't have any comments yet