Question: LISTING 19.6 import java.io.*; /** * BackPainAnaylyzer demonstrates the use of a binary decision tree to * diagnose back pain. */ public class BackPainAnalyzer

LISTING 19.6 import java.io.*; /** * BackPainAnaylyzer demonstrates the use of abinary decision tree to * diagnose back pain. */ public class BackPainAnalyzer{ } /** * Asks questions of the user to diagnose amedical problem. */ public static void main(String[] args) throws FileNotFoundException { System.out.println("So,you're having back pain."); } DecisionTree expert = new DecisionTree ("input.txt"); expert.evaluate();

LISTING 19.6 import java.io.*; /** * BackPainAnaylyzer demonstrates the use of a binary decision tree to * diagnose back pain. */ public class BackPainAnalyzer { } /** * Asks questions of the user to diagnose a medical problem. */ public static void main(String[] args) throws FileNotFoundException { System.out.println("So, you're having back pain."); } DecisionTree expert = new DecisionTree ("input.txt"); expert.evaluate(); OUTPUT So, you're having back pain Did the pain occur after a blow or jolt? Y Do you have difficulty controlling your arms or legs? N Do you have pain or numbness in one arm or leg? Y You may have a muscle or nerve injury. import jsjf.*; import java.util. *; import java.io.*; * * The DecisionTree class uses the LinkedBinaryTree class to implement a binary decision tree. Tree elements are read from a given file and then the decision tree can be evaluated based on user input using the * evaluate method. * * * @author Java Foundations *@version 4.0 */ public class DecisionTree { private LinkedBinaryTree tree; /** * Builds the decision tree based on the contents of the given file * @param filename the name of the input file * @throws FileNotFoundException if the input file is not found */ public DecisionTree (String filename) throws FileNotFoundException { * File inputFile = new File (filename); Scanner scan = new Scanner (inputFile); } int numberNodes scan.nextInt (); scan.nextLine(); int root = 0, left, right; List nodes = new java.util.ArrayList (); for (int i = 0; i < numberNodes; i++) nodes. add (i, new LinkedBinaryTree (scan.nextLine())); while (scan.hasNext()) { root scan.nextInt (); left scan.nextInt (); right scan.nextInt (); scan.nextLine(); nodes. set (root, new LinkedBinaryTree ((nodes.get (root)).getRootElement (), nodes.get (left), nodes.get (right))); } tree nodes.get (root); * Follows the decision tree based on user responses. */ public void evaluate () { LinkedBinaryTree current = tree; Scanner scan = new Scanner (System.in); while (current.size() > 1) { System.out.println (current.getRootElement()); if (scan.nextLine().equalsIgnoreCase ("N")) current = current.getLeft (); else current = current.getRight (); System.out.println (current.getRootElement()); import java.io.*; /** * BackPainAnaylyzer demonstrates the use of a binary decision tree to * diagnose back pain. */ public class BackPainAnalyzer { /** * Asks questions of the user to diagnose a medical problem. */ public static void main (String[] args) throws FileNotFoundException { System.out.println ("So, you're having back pain."); DecisionTree expert = new DecisionTree ("input.txt"); expert.evaluate();

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!