Programming Assignment 5: Twenty Questions

Learning Goals
The goal of this assignment is to give everyone in the class practice in creating a simple android application and to give you another opportunity to design an interesting and effective set of classes to solve a problem. You will also have an opportunity to practice your use of databases in android.

The application you are to build will play a game of 20 questions where the user thinks of an animal and the application asks yes or no questions until it finds the right answer. 

The basic algorithm is the following. The application will construct a binary tree where the nodes are labeled with yes/no questions and the leaves are guesses.  It starts out with a tree that has a single node containing the guess "Are you a zebra?"  If the user is thinking of a Zebra then the application wins, having guessed it right off. Otherwise, the application asks the user for a question Q which is "no" for a zebra and "yes" for their animal. For example, if they were thinking "shark", the question could be "Is your animal a carnivore?"  The application then replaces the "zebra" node in the tree with the question "Q" and adds two children, the "yes" child is "shark" and the "no" child is "zebra".  The next time the game is played, it starts at the root asking yes or no questions until it reaches a leaf. If the guess is incorrect, it repeats the process above replacing the leaf with a question node "Q" that has two children, the original leaf and the user's new animal.

You should encapsulate the tree-building part of the code in a class which initially will store the tree in a Java object which is built from scratch everytime. This can later be extended to use an android Database that will grow each time the application is used, and later (though not for this assignment) to a web-based REST interface. 

I would suggest first writing a straight Java implementation of the code in the simplest way possible with no database, and then extending this to an android application using a database.  This assignment can be completed using very little code and you should strive for a short, simple, and elegant solution!

A small prize will be given for the simplest and most elegant solution!

For this Thursday, you should complete the non-Android Java version of the program and be prepared to discuss it in class, focusing on the object-oriented design you are using.

For next Tuesday, complete the Android version, upload the code to your github account and create a short screencast or movie showing the program working in an emulator or on a device.