In this homework, you will gain more experience using if/else-type statements by writing a so-called "expert system", or a program that behaves like a human expert for a particular type of problem. For this assignment you will develop a somewhat silly expert system based on many variations of a humorous flowchart floating around the Internet. You can see a more serious example of an expert system in the assignment from spring 2005. The problem domain being considered in this assignment is "how to decide your role in serving an evil genius."
We have provided an initial version of the code (called skeleton code because it provides the framework or "skeleton" on which you will build) in ProblemSolver.java. In particular we supply the string constants you are to use for the questions, answers, and actions. You will also need to download and use the YesNoExtractor class contained in the file YesNoExtractor.class (right-click and select "save as"). The YesNoExtractor.class file must be in the same directory as the ProblemSolver.java file for your program to work correctly.
The YesNoExtractor class supports the following methods:
The tool you will design and produce is based on the following diagram, which is based on several humorous versions found on the Net. All flowcharts show something -- this one shows how to figure out which role you are suited to if you were to serve an evil genius. (in jest, of course!).
This flowchart is a bit difficult to implement for this homework, so we are providing a slightly modified version below. It is the version below that you need to implement for this homework. It's essentially the same thing with a few changes (fewer questions, etc.).
In this diagram, as in most flowcharts, questions for the user (which will become calls to YesNoExtractor.askUser() in your code) are represented as diamonds. Final resolutions (which the program prints out before terminating) as rectangles (in this diagram, either green or purple). The particular answer (yes or no, for this flowchart) that moves to another box is listed on the arrow. Note that the "Start here" is just a indication of where to start, and need not be printed (although you should be printing a legend before you ask the first question).
Currently the skeleton code implements only a single question of the flowchart, and doesn't do much else. Note that you should use the exact string constants given in the skeleton code -- you can just call System.out.println(A_CODING);, for example, to print out the resolution shown on the lower right of the flowchart.
Note that there are certain parts of the flowchart that are repeated. In particular, there are 3 paths that can get you to the "Minion" and "Lieutenant" resolutions and 2 paths to the "Doorstop" resolution. It's fine to have that resolution repeated throughout your code (i.e. you can have 3 separate print statements with that resolution, if you need to do so).
The good programming practices from HW 1 need to be in this homework as well.
We are not providing a sample execution for this program. As the homeworks in the course progress, less detailed information will be provided, and it is up to you to fill in the detail that is left out (in this case, the execution run).
This program will require both if-else-if statements, as well as nested if's. You MUST use if-else-if's in this homework.
Lastly, note that you can call System.exit(0); from anywhere in your code. This will cause the Java program to immediately stop, even if it is in a nested if statement. Depending on how you write your program, you may not need to use this.