Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Use the following file for this assignment. It contains the names given to male

ID: 3667354 • Letter: U

Question

Use the following file for this assignment.

It contains the names given to male and female babies in 2013, along with the counts for each name in the list.

Once you have downloaded the file, look at it in a text editor to help you figure out how you will parse it.

Use Map<String,Integer> and Set<String> objects to help you determine the following:

- How many unique female names were there?

- How many unique male names were there?

- How many names were given to both males and females ("unisex" names)?

- How many female babies have the same name you do?

- How many male babies have the same name you do?

Submit your answers to the above questions, along with your .java file(s).

For this assignment, a single Java file that includes a main method is acceptable.

Feel free to explore additional questions (e.g. most common male and female names, least common names, etc.).

Explanation / Answer

Please note that i have wrote program for first 3 of your questions, but i dont understood the remaining question.

Please comment about the last 2 questions and i would answer for that too.

================================================================

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.HashSet;
import java.util.Set;

public class NameProcess {
   public static void main(String[] args) throws Exception {
       BufferedReader reader = new BufferedReader(new FileReader(new File(
               "input.txt")));

       Set<String> uniqueMaleNames = new HashSet<>();
       Set<String> uniqueFeMaleNames = new HashSet<>();

       String line;
       while ((line = reader.readLine()) != null) {
           String[] data = line.split(",");
           String name = data[0];
           String gender = data[1];
           Integer temp;
           if ("F".equalsIgnoreCase(gender)) {
               uniqueFeMaleNames.add(name);
           } else {
               uniqueMaleNames.add(name);
           }

       }

       System.out.println("Number of unique Female names : "
               + uniqueFeMaleNames.size());
       System.out.println("Number of unique Male names : "
               + uniqueMaleNames.size());

       Set<String> commonNames = new HashSet<String>(uniqueFeMaleNames);
       commonNames.retainAll(uniqueMaleNames);
       System.out
               .println("Number of common names in female and male (unisex) : "
                       + commonNames.size());

   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote