Answered You can hire a professional tutor to get the answer.
Java method called 1) playLoop(Animal animalList, Animal answer) step 1 use a new integer variable called "questionsLeft". Set it equal to 20.
Java method called
1) playLoop(Animal[] animalList, Animal answer)
step 1 use a new integer variable called "questionsLeft". Set it equal to 20.
step 2 Enter a loop, and keep looping until (questionsLeft == 0) . Each iteration, do the following:
a) Print out a message telling the player how many questions they have left.
b) Print out a list of choices the player can make:
1. ask a relational question
2. ask an existential question
3. make a guess
4. lookup an animal in the database (this is a free move, i.e. should not count against the players 20 question limit)
5. quit
c) Setup a new Scanner instance to read from System.in. Prompt the player for input (and keep reprompting them until they enter 1, 2, 3, 4, or 5).
d) Perform the following actions based on the players input:
1. make a new instance of RelationalQuestion . You will have to pass the "animalList" array and the "answer" into the instance's constructor. You must then call its "AskQuestion()" method.
2. make a new instance of ExistentialQuestion . You will have to pass the "animalList" array and the "answer" into the instance's constructor. You must then call its "AskQuestion()" method.
3. Prompt the user to enter the name of an animal. If answer.getName().equals(usersGuess) then print out a win message and return.
4. Prompt the user to enter the name of an animal. Search your animalList array for an animal with the same name, and if you find one, then print it out. Else, tell the player that the animal does not exist in the database.
5. Print a goodbye message and return.
"AskQuestion()" will return a boolean (true if that question should count against the users alloted 20, or false if it shouldn't). If the user picked 1 or 2 and "AskQuestion()" returned true then decrement questionsLeft by 1. Else if the user picked 3, then decrement questionsLeft by 1. Else, do not decrement questionsLeft (option 4, looking up an animal in the database is a "free move").
step 3 If the loop finishes, then the player was not able to guess the animal within 20 questions (else the method would have returned when they did so). Offer the player one final chance to enter an animals name, and compare it to the answer (similar to option 3 in the loop). If they guessed, then print out a win message. Else, print out a message telling them what the answer was. Finally, return.