Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

KJO-ITD Java Programming

Exceptions & File I/O

Description

The text files boynames.txt and girlnames.txt, contains a list of the 1,000 most popular boy
and girl names in the United States for the year 2003 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 and then the
number of registered births using that name in the year. For example the girlnames.txt file
begins with:

Emily 25494
Emma 22535
Madison 19986

This indicates that Emily was the most popular name with 25,494 registered names,
Emma was the second most popular with 22,532, and Madison was the third most
popular with 19,986.

Write a program that will read both the girls and boys files into memory using arrays. If
the files do not exist then display a message to the screen indicating the specific file name
does not exist and update file errorLog.txt by appending the file name that caused the error,
then terminate the program. The file errorLog.txt will contain the list of all the file names,
each on a separate line, that this program had problems opening them for reading. On the
other hand, id the files do exist then proceed to reading them into arrays, one for boys and
one for girls, then prompt the user to input a name . The program should search through
both arrays. If there is a match, then it should output the popularity ranking and the
number of registered names. The program should also indicate if there is no match.
The program should then prompt the user if they which to search for another name or end
the program.

Sample Input & Output, if the user enters the name “Justice”:

Please enter a name to search for:


Justice
Justice is ranked 456 in popularity among girls with 655 registered names.
Justice is ranked 401 in popularity among boys with 653 registered names.

Would you like to search for another name: (Yes / No):


No
Good Bye…

Al-Marri(21156) Page 1 of 2
KJO-ITD Java Programming

Sample Input & Output, if the user enters the name “Walter” followed by another entry
for the name “AUK”:

Please enter a name to search for:


Walter
Walter is not ranked among the top 1000 girl names.
Walter is ranked 356 in popularity among boys with 775 registered names.

Would you like to search for another name: (Yes / No):


Yes

Please enter a name to search for:


AUK
AUK is not ranked among the top 1000 girl names.
AUK is not ranked among the top 1000 boy names.

Would you like to search for another name: (Yes / No):


No
Good Bye…

Sample Output, if the program could not find the input text files, boynames.txt

Error….File boysnames.txt could not be found.


Program terminating.

And the file errorLog.txt would contain the following line, if this is the first time you ran
the program

boynames.txt

The following output of file errorLog.txt would indicate:


boysnames.txt
boysnames.txt
girlsnames.txt

That the program failed three times to read the input file, first failure was due to file
boysnames.txt, the second failure was due to file boysnames.txt and the third failure was due to
the file girlsnames.txt

Due Date: Submit your code on December 12th. Please make sure you test your program
to meet the requirements mentioned above and also on program style, alignment of code,
comments, have at least a comment with your name, date.

Al-Marri(21156) Page 2 of 2

You might also like