Attached the code. Please help!
package com.codegym.task.task08.task0815;
import java.util.HashMap;
import java.util.HashSet;
/*
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.
Requirements:
1. The program should not display text on the screen.
2. The program should not read values from the keyboard.
3. The createMap() method must create and return a HashMap
that has (String, String) elements and contains 10 entries that
represent (last name, first name) pairs.
4. The getSameFirstNameCount() method must return the
number of people that have the same first name.
5. The getSameLastNameCount() method must return
the number of people that have the same last name.
*/
public class Solution {
public static HashMap<String, String> createMap() {
//write your code here
HashMap<String, String> map = new HashMap<String, String>();
map.put("Jack", "Jill");
map.put("Ja", "Jane");
map.put("John", "Jill");
map.put("Kane", "Kim");
map.put("Henry", "Regan");
map.put("Brad", "Jan");
map.put("Cone", "Regan");
map.put("Winner", "Randy");
map.put("Taker", "Jimmy");
map.put("Rock", "Kate");
// map.put("Rock", "Kim");
return map;
}
public static int getSameFirstNameCount(HashMap<String, String> map, String name) {
//write your code here
int fncou = 0;
HashSet<String> fname = new HashSet<String>(map.values());
// Iterator itr = fname.iterator();
for (String s : fname) {
if (s.equals(name)) {
fncou ++;
}
}
return fncou;
}
public static int getSameLastNameCount(HashMap<String, String> map, String lastName) {
//write your code here
int lncou = 0;
HashSet<String> lname = new HashSet<String>(map.keySet());
// Iterator itr = fname.iterator();
for (String l : lname) {
if (l.equals(lastName)) {
lncou ++;
}
}
return lncou;
}
public static void main(String[] args) {
}
}