I was wondering if anyone has any insight with the problem I'm having with the following question...
Write a Java application that reads two files into separate ArrayLists. Once you have read and stored the names prompt the user to enter in a boy’s name and a girl’s name. Check to see if the name is in the ArrayList and notify the user accordingly. Assuming the files are sorted from most popular to least popular also display the “rank” of the name if it is found. (Hint: remember the indices of an array are off by one). You can do all of this work in the main method. You can hardcode the names of the files.
A more elegant solution would be to use methods to break up these tasks. Implement the following:
• readNameFile: takes a string (the name of the file) as an argument and returns an
ArrayList with 200 names. Note: all file I/O is done inside of this method.
• searchForName: takes an ArrayList and a String as arguments. Returns the index of the name if it is in the ArrayList, -1 if it is not. Use linear search to accomplish this task.
The following is an example of the output...
java Names Please enter one girl and one boy name separated by a new line:
James Suzie was not found in the list of 200 most popular girl names.
James was found, and was ranked 17 by popularity.
(Bold indicates user input.)
The following is what I have for the code:
The problem I am encountering is when I run the program the boyIndex doesn't find the rank properly, for example, in the above output name example of "James" ranking in 17 of popularity, when I run my code it ranks "James" at 217 in popularity (there's only 200 names in the file). The girls name has no issues, and the boyIndex is written the same way, I'm not sure where the problem is.