Homework J3

Due: Friday, 7 October 2005 by 10 a.m.



Home | Resources | Homeworks | Slides | Labs | Contacts | Submit | Forums

Purpose

In this homework, you will gain more experience using if/else-type statements by writing a so-called "expert system" that attempts to diagnose a problem and recommend a course of action.  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 more serious examples of expert systems in the assignments for last fall or last spring.  Your code should be in a ProblemSolver class in a file named ProblemSolver.java. 

Background

In this assignment you develop a class for representing and manipulating a (light-hearted) diagnostic tool. A diagnostic tool is an example of an expert system, or a program that behaves like a human expert for a particular problem domain. The problem domain being considered in this assignment is in fact the general approach to problem solving on the job.

Skeleton Code

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.

Class YesNoExtractor

The YesNoExtractor class supports the following methods:

The class also defines the following constants:

You can use these constants, as shown in the example code for ProblemSolver.java, to write more readable code. Constants such as these allow you to "hide" the exact behavior of the askUser() method (whether it returns true or false for yes or no) and are often good programming practice.

The Flowchart

The tool you will design and produce is based on the following diagram, which is based on several humorous versions fount on the Net (but usually with more profanity):

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.  Recommended actions (which are simply printed out to the user) are represented as rectangles (in this diagram, they are light blue).  Final resolutions (which the program prints out before terminating) as ovals (in this diagram, either green or red).  Note that the "Start here" is just a indication of where to start, and need not be printed.

Currently the skeleton code implements only a single question of the flowchart, and skips immediately to one of the two "resolution" steps. Note that you should use the exact string constants given in the skeleton code, and not the somewhat terser versions in the flowchart above.

Miscellaneous Notes

The good programming practices from HW J1 need to be in this homework as well.  However, you do not have to echo input that was read via the askUser() method.

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.

Recall 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.

Submission

When you are finished, submit the ProblemSolver.java file.