Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a guessing game called \"Does It Have Legs?\", in which you think of an a

ID: 3668989 • Letter: C

Question

Create a guessing game called "Does It Have Legs?", in which you think of an animal and the computer tries to guess what it is. The game continually becomes "smarter" as you play because you teach it how to become more specific with its questions. For example, a typical game session might proceed as follows:

Computer: Does the animal you are thinking of have legs?

Player: Yes

Computer: Is it a dog?

Player: Yes

Computer: Yay! I win. Do you want to play again?

Player: Yes

Computer: Does the animal you are thinking of have legs?

Player: Yes

Computer: Is it a dog?

Player: No

Computer: I give up. What was your animal?

Player: Horse

Computer: Type a question for which the answer is Yes for Dog but No for Horse.

Player: Does it live in the house?

Computer: Do you want to play again?

Player: Yes

Computer: Does the animal you are thinking of have legs?

Player: Yes

Computer: Does it live in a house?

Player: No

Computer: Is it a horse?

PLayer: No

Computer: I give up. What was your animal?

Player: Cow.

Computer: Type a question for which the answer is Yes for Horse but No for Cow.

Player: Do people ride it?

Computer: Do you want to play again?

Player: Yes

Computer: Does the animal you are thinking of have legs?

Player: Yes

Computer: Does it live in the house?

Player: No

Computer: Do people ride it?

Player: No

Computer: Is it a cow?

Player: Yes

Computer: Yay! I win. Do you want to play again?

Player: No

(Hint: You might want to look up "binary trees" on the internet as a method do organize this application.)

Save the application as DoesItHaveLegs.java

Explanation / Answer

import java.util.*;
public class doesithavelegs {
   public static void main(String[] args){
       Scanner ut = new Scanner(System.in);
       String[] g = new String[150];
       String[] a = new String[100];
       for(int x=0;x< 20;x++){
       System.out.println("Think of an animal.");
       System.out.println("Does your animal have 4 legs?");
       g[0]=ut.nextLine();
       if(g[0].equalsIgnoreCase("yes")){
           System.out.println("Is your animal a dog?");
           g[1]=ut.nextLine();
           if(g[1].equalsIgnoreCase("yes")){
                   System.out.println("I won would you like to play again?");
                   a[0]=ut.nextLine();
               if (a[0].equalsIgnoreCase("no")){
                   x--;
               }
               else{
                   x++;
               }
           }
               else if(g[1].equalsIgnoreCase("no")){
                   System.out.println("I give up what is your animal");
                   g[5]=ut.nextLine();
                   System.out.println("Type a question for which the answer is yes for Dog but no for.");
                   g[4]=ut.nextLine();
           }
       else if(g[0].equalsIgnoreCase("no")){
               System.out.println("I give up what is your animal");
               g[2]=ut.nextLine();
               System.out.println("Type a question for which the answer is yes for Dog but no for.");
               g[3]=ut.nextLine();
               System.out.println("I won would you like to play again?");
               a[1]=ut.nextLine();
               if (a[1].equalsIgnoreCase("no")){
                   x--;
               }
               else{
                   x++;
               }
           }  
       }
   }
   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote