Java代写:COMSC201 The 20 Questions Guessing Game

用Java代写一个类似电视中的20 Questions Guessing Game,回答20个问题,斩将过关。问题以及答案存储在XML文件中,需要对文件进行解析。

Overview

For this project, you will design and implement an application from scratch. For this reason, I have not outlined any classes or methods for you to implement. You will need to design these yourself before beginning implementation. You will also investigate one Java class independently and use it in your project; being able to learn how to use a class on your own is a valuable skill. That being said, do not hesitate to contact the instructors for guidance with any aspect of the project!

Goals:

  1. design a program from scratch
  2. implement your design
  3. read from an xml file
  4. find and use a Java class we have not seen in previous assignments
  5. use packages to organize your project.

The 20 Questions Guessing Game

The computer shows the user a list of things (for example, an animal) and asks the user thinks of one of them. Then the computer asks a series of yes/no questions to try to determine which thing the user is thinking of. In this variation of the game, the choice of things is pre-specified and is shown to the user at the start.

Requirements

Your final product should be an executable application with a nicely designed GUI. You must have at least 16 pre-specified answers.

XML files

You will need to read in an xml file containing the data for the game; this will correspond to a “decision tree,” where each node has a question and two children corresponding to answers “yes” and “no.” Refer to this page on XML file reading.

You will be graded on the “style” of your XML file – i.e., do not have anything about arithmetic expressions in it!

Use a new Java class

Investigate and use a Java class that we have not discussed in lecture. This could be one of the many GUI classes offered, for instance. Learn how to use the class from the Java tutorial or other resources.

Packages

Using what you learned in Lab 10, make sure to come up with a sensible organization of your code into packages. Eclipse lets you do this through its GUI.

Unrestricted Guessing Game

In this part, implement an “unrestricted” 20 questions game:

  • Extend your application to let the user pick a thing that is not on the pre-specified list.
    • Start asking questions in the same way.
    • If the computer gets to a point in the tree where there is only one thing remaining, and guesses incorrectly (because the thing the user is thinking of is unknown), learn the thing.
    • This will require asking the user:
      • What thing were you thinking of?
      • Please give me a yes/no question that would have determined your thing.
      • Is the answer to your question yes or no?
    • Modify your decision tree based on the answer so that the new thing is in list for a new round that is started within the session
    • OPTIONAL BONUS: Save the modified decision tree to an XML file for the next game (this would involve writing an xml file).

Process

Be sure to break your process into smaller steps:

  1. design and implement the user interface (this may be where you include your chosen Java class)
    • think of required information that needs to be displayed to the user
    • think of required interaction with the user
    • sketch out the GUI
    • implement a shell version of the GUI where method stubs are hooked up to buttons, etc.
  2. design and implement the backend
    • think of the data (state) that needs to be stored -> this should help you decide what classes to have (and their instance properties)
    • think of the behavior that must be supported by the various classes -> this should help you decide what instance methods are required
    • create skeleton class files
    • implement the instance methods, testing constantly!
  3. DEBUG :)