Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialMLUNGISI NGQEBE
Courses Plus Student 1,152 Pointshow to build and display a decision tree in the main
import java.util.Scanner;
import javafx.application.Application; import javafx.event.ActionEvent; import javafx.event.Event; import javafx.event.EventHandler; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.TextArea; import javafx.scene.control.TextField; import javafx.scene.input.KeyCode; import javafx.scene.input.KeyEvent; import javafx.scene.layout.HBox; import javafx.scene.layout.StackPane; import javafx.scene.layout.VBox; import javafx.stage.Stage;
public class main { public static void main(String []args) {
LinkedBinaryTree.Node<String> rootNode=new LinkedBinaryTree.Node<String>("IS YOUR MONTHLY INCOME 38 DOLLARS OR LESS",null ,null ,null );
LinkedBinaryTree.Node<String> leftParent=new LinkedBinaryTree.Node<String>("Declared in Extreme/Absolute poverty\n Is the cause of your predicament generational?\n In other words is your poverty inherited", rootNode, null, null);
rootNode.setLeft(leftParent);
LinkedBinaryTree.Node<String> rightChildOfLeftParent=new LinkedBinaryTree.Node<String>("If so you are Eligible for a government Social grant",leftParent , null, null);
leftParent.setRight(rightChildOfLeftParent);
LinkedBinaryTree.Node<String> LeftChildOfLeftParent=new LinkedBinaryTree.Node<String>("you fall on the waiting list before receiving social grant", leftParent, null, null);
leftParent.setLeft(LeftChildOfLeftParent);
LinkedBinaryTree.Node<String> rightParent=new LinkedBinaryTree.Node<String>("Your are not in extreme Poverty\n Are you living under the world standard monthly income", rootNode, null, null);
rootNode.setRight(rightParent);
LinkedBinaryTree.Node<String> childOfRightParent=new LinkedBinaryTree.Node<String>("your are relatively power",rightParent, null, null);
rightParent.setRight(childOfRightParent);
Scanner sc= new Scanner(System.in);
LinkedBinaryTree.Node<String> n=rootNode;
System.out.print(n.getElement());
while(n.getLeft()!=null && n.getRight()!=null) {
switch(sc.nextLine()) {
case "yes":
// n= n.getLeft();
System.out.print(n.getLeft().getElement());
break;
case "no":
// n= n.getRight();
System.out.print(n.getRight().getElement());
break;
default:
System.out.print("error");
break;
}
}}}