SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Walter Savitch ,kenrick Mock
Chapter:
Collections Maps And Iterators
Exercise:
Programming Projects
Question:4 | ISBN:9780132830317 | Edition: 5

Question

The text files boynames.txt and girlnames.txt, which are included in the source code for this book, contain lists of the 1,000 most popular boy and girl names in the United States for the year 2005, as compiled by the Social Security Administration.

These are blank-delimited files where the most popular name is listed first, the second most popular name is listed second, and so on to the 1,000th most popular name, which is listed last. Each line consists of the first name followed by a blank space followed by the number of registered births in the year using that name. For example, the girlnames.txt file begins with

Emily 25494

Emma 22532

This indicates that Emily is the most popular name with 25,494 registered namings, Emma is the second most popular with 22,532, and so on.

Write a program that determines how many names are on both the boys’ and the girls’ list. Use the following algorithm:

• Read each girl name as a String, ignoring the number of namings, and add it to a HashSet object.

• Read each boy name as a String, ignoring the number of namings, and add it to the same HashSet object. If the name is already in the HashSet , then the add method returns false . If you count the number of false returns, then this gives you the number of common namings.

• Add each common name to an ArrayList and output all of the common names from this list before the program exits.


TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Sorry the answer is not available at the moment…

If you are able to find the answer, please make sure to post it here. So that your Juniors have smile on their lips and feel happy.

Spread the 'tradition of sharing'.