Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I'm writing a 20 questions java program and keep getting errors for the QuestionNode and inability to find the symbol. Can you please help me

I'm writing a 20 questions java program and keep getting errors for the QuestionNode and inability to find the symbol.

Can you please help me with what I need to add to this to remove these errors? Thanks!!!

import java.util.*; import java.io.*; public class QuestionTree { private QuestionNode rootOfTree; private Scanner console; public QuestionTree() { rootOfTree = new QuestionNode("computer"); console = new Scanner(System.in); } public void read(Scanner input) { while(input.hasNextLine()) { rootOfTree = readHelper(input); } } private QuestionNode readHelper(Scanner input) { String type = input.nextLine(); String data = input.nextLine(); QuestionNode root = new QuestionNode(data); if (type.contains("Q:")) { root.yesNode = readHelper(input); root.noNode = readHelper(input); } return root; } public void write(PrintStream output) { if (output == null) { throw new IllegalArgumentException(); } writeTree(rootOfTree, output); } private void writeTree(QuestionNode rootOfTree, PrintStream output) { if (isAnswerNode(rootOfTree)) { output.println("A:"); output.println(rootOfTree.data); } else { output.println("Q:"); output.println(rootOfTree.data); writeTree(rootOfTree.yesNode, output); writeTree(rootOfTree.noNode, output); } } public void askQuestions() { rootOfTree = askQuestions(rootOfTree); } private QuestionNode askQuestions(QuestionNode current) { if (isAnswerNode(current)) { if (yesTo("Would your object happen to be " + current.data +"?")) { System.out.println("Great, I got it right!"); } else { System.out.print("What is the name of your object? "); QuestionNode answer = new QuestionNode(console.nextLine()); System.out.println("Please give me a yes/no question that"); System.out.println("distinguishes between your object"); System.out.print("and mine--> "); String question = console.nextLine(); if (yesTo("And what is the answer for your object?")) { current = new QuestionNode(question, answer, current); } else { current = new QuestionNode(question, current, answer); } } } else { if (yesTo(current.data)) { current.yesNode = askQuestions(current.yesNode); } else { current.noNode = askQuestions(current.noNode); } } return current; } public boolean yesTo(String prompt) { System.out.print(prompt + " (y/n)? "); String response = console.nextLine().trim().toLowerCase(); while (!response.equals("y") && !response.equals("n")) { System.out.println("Please answer y or n."); System.out.print(prompt + " (y/n)? "); response = console.nextLine().trim().toLowerCase(); } return response.equals("y"); } private boolean isAnswerNode(QuestionNode node) { return (node.yesNode == null || node.noNode == null); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions

Question

Sysco coperation is one of the north ameria's leading distributors

Answered: 1 week ago