In this assignment you will implement the 20 Questions Game, described in class, using Java. This is a lot of fun but also requires some careful design. There are also two completely optional bonus problems this week. Most students find this assignment to be more challenging than Assignment 2, so please try to start early!
Like last week, there is a short part 0, due this Sunday, September 17 at 11:59pm that asks you to think about the problem and start designing your solution. This week, however, this part of the assignment is a little more open ended. All we want you to do is read through the assignment and run the provided (compiled) code. Then, describe in a paragraph or so the structure of how you will design your program. In particular, describe in as much detail as possible, the structure of your nodes that will keep track of the information needed to play the game. Consider how you will represent questions, how you will represent animals, and how you will link them together. Write your initial design thoughts in a file called Part0.txt and submit it using cs60submit. This week, cs60submit will ask you what problem you are submitting. Part0.txt is problem 0, the rest of the files are problem 1. It will help to place Part0.txt in a different place from the files for problem 1 so that you can use cs60submitall (see below).
You will find a compiled version of our solution to this assignment in a file called twenty_questions.class in the directory /cs/cs60/assignments/assignment3. Note that Node.class is the compiled version of Node.java, which in our solution is the class describing a single node in the binary tree. Play this game by running
java twenty_questionsso that you get a good feel for how the program should work! Here are the requirements for your program:
The only slightly "grungy" thing is that of getting input from the user. To demonstrate how input works in Java, we have provided a small demonstration program called IO.java in the directory /cs/cs60/assignments/assignment3. You may use any and all of this code in your own code.
Think about the design of your code before starting to program. We will be grading this program for both functionality and good style. Regarding style, keep the following in mind:
Please submit all of the files that comprise your implementation of this game. Undoubtedly, you will have a file describing a node in the binary tree as well as the executable class. If you wish, you may have other files as well. You can use cs60submit multiple times, once for each file that you need to submit. Alternatively, if you type cs60submitall and hit the RETURN key, all of the java files in the directory in which you are currently located will be submitted. cs60submitall will show you the name of each file that it is sumbitting for you.
In class (if not Thursday, then we will on Tuesday) we looked at B-trees (specifically, "2-3-4 trees") - a beautiful data structure for the Dictionary abstract data type. The wonderful thing about this data structure is that all operations can be performed in O(log n) time. Implement a B-tree class in a file called Btree.java. This class should implement the abstract data type provided in the interface DictionaryADT.java in /cs/cs60/assignments/assignment3/bonus. Specifically, the interface supports the following operations:
In addition, you should have a method int height() which returns the height of the tree. Recall from class that the height of a tree is the length of the longest path from the root to a leaf node, where the leaf nodes are assumed to be "null" nodes. Thus, a tree comprising just a single root node with two null children has height 1. An empty tree is a "null" tree and thus has height 0. Do you see why this height method wasn't specified in the DictionaryADT interface, even though we want to have it implemented in the Btree class?
Make sure that your code is well-structured, clean, and readable. Submit your file Btree.java and any other files which it requires. Notice that Btree.java defines a B-tree and is not executable. However, you should write a thorough tester program to make sure that your class functions correctly, and you should submit this tester with your program. We will test your Btree class using our own tester programs.