Write a Java program that learns about a universe of your choice by asking the user yes/no questions. For example, your program might learn about animals by having the following dialogue with its user. (User responses are in uppercase.)
Think of an animal and I will guess it.
Does it have legs? YES
Is it a cat? YES
I win! Continue? YES
Think of an animal and I will guess it.
Does it have legs? NO
Is it a snake? YES
I win! Continue? YES
Think of an animal and I will guess it.
Does it have legs? NO
Is it a snake? NO
I give up. What is it? EARTHWORM
Please type a question whose answer is yes for an
earthworm and no for a snake:
DOES IT LIVE UNDERGROUND?
Continue? YES
Think of an animal and I will guess it.
Does it have legs? NO
Does it live underground? NO
Is it a snake? NO
I give up. What is it? FISH
Please type a question whose answer is yes for a
fish and no for a snake:
DOES IT LIVE IN WATER?
Continue? NO
Good-bye.
The program begins with minimal knowledge about animals: It knows that cats have legs and snakes do not. When the program incorrectly guesses “snake” the next time, it asks for the answer and also asks for a way to distinguish between snakes and earthworms.
The program builds a binary tree of questions and animals. A YES response to a question is stored in the question’s left child; a NO response is stored in the question’s right child.
We need at least 10 more requests to produce the solution.
0 / 10 have requested this problem solution
The more requests, the faster the answer.