Question: In this lab, you will implement a guess your name game where the computer finds a name in a sorted list of names. The computer
In this lab, you will implement a guess your name game where the computer finds a name in a sorted list of names. The computer will use this method to guess your last name: This program tries to guess your last name, but you have to give some hints. Does your name come before "LANGLITZ" in the dictionary? (Y/N) y Does your name come before "DURSO" in the dictionary? (Y/N) y Does your name come before "BURROWS" in the dictionary? (Y/N) n . Is your name "DUKE"? (Y/N) y 1. Read names from census web site and sort them Start out with a program that reads all names from the "last names" file at http://www2.census.gov/topics/genealogy/1990surnames/dist.all.last. Discard the statistical information. Sort the names, using Collections.sort. Use this code outline: public class NameGuesser { private ArrayList
2. Now you will implement the method in NameGuesser that guesses the name, call the method guessName. At the beginning of the search, set low to 0 and high to the maximum index of the names list. Set mid to the average of low and high, and then ask the user if the name comes before the list entry at index mid. Depending on the answer, update low or high. If low >= high, ask if the name matches. Write the code for your guessName method and add it to NameGuesser? 3. Write a separate class called NameGame that that instantiates an instance of NameGuesser to play the game. 4. How many entries does your names list have? How many guesses does your program need to make until it has guessed the user's name or given up? (Use big-Oh for your answer.)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
