I have no idea based on the code I have written, why it is giving an error for the third condition. I have specified 10 entries as (last name, first name) pair. Thanks in advance.
package com.codegym.task.task08.task0815;
import java.util.HashMap;
import java.util.HashSet;
/*
Census
*/
public class Solution {
public static HashMap<String, String> createMap() {
//write your code here
HashMap<String, String> names = new HashMap<String, String>();
names.put("Brewster", "John");
names.put("Jones", "Jane");
names.put("Fudge", "Mike");
names.put("Tyson", "Mike");
names.put("Cena", "John");
names.put("Nakamura", "Shinsuke");
names.put("Mysterio", "Ray");
names.put("Orton", "Randy");
names.put("Dwayne", "Johnson");
names.put("Dwayne", "John");
return names;
}
public static int getSameFirstNameCount(HashMap<String, String> map, String name) {
//write your code here
int count = 0;
for(String first: map.values()) {
if(first.equals(name)) count++;
}
return count;
}
public static int getSameLastNameCount(HashMap<String, String> map, String lastName) {
//write your code here
int count = 0;
for(String last: map.keySet()) {
if(last.equals(lastName)) count++;
}
return count;
}
public static void main(String[] args) {
}
}