Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- while(!temp.isLeaf()) {
- System.out.print(temp.root + "? ");
- String rootAnswer = scanner.nextLine();
- if (rootAnswer.equals("Yes")) {
- //add variables to differentiate
- temp = temp.getRightSubtree();
- System.out.print(temp.getData() + "? ");
- String firstRightLeaf = scanner.nextLine();
- if (firstRightLeaf.equals("Yes") && temp.getRightSubtree() == null && temp.getLeftSubtree() == null) {
- System.out.println("I guessed it!");
- System.out.print("Would you like to play again? ");
- String yesOrno = scanner.nextLine();
- if (yesOrno.equals("Yes"))
- temp = bt;
- else
- break;
- }
- else if (firstRightLeaf.equals("No") && temp.getRightSubtree() == null && temp.getLeftSubtree() == null) {
- System.out.print("What is your animal? ");
- String animal = scanner.nextLine();
- System.out.print("Provide a question that uniquely identifies your animal? ");
- String question = scanner.nextLine();
- BinaryTree<String> save = bt;
- temp = bt.getRightSubtree();
- temp.setData(question);
- temp.setLeftSubtree(save);
- BinaryTree<String> animal2 = new BinaryTree<>(animal);
- temp.setRightSubtree(animal2);
- System.out.print("Would you like to play again? ");
- String yesOrno = scanner.nextLine();
- if (yesOrno.equals("Yes"))
- temp = bt;
- else
- break;
- }
- else if(firstRightLeaf.equals("Yes") && !temp.isLeaf()) {
- }
- else if(firstRightLeaf.equals("No") && !temp.isLeaf()) {
- System.out.println(temp.getLeftSubtree().getData() + "? ");
- }
- }
- else if (rootAnswer.equals("No")) {
- temp = bt.getLeftSubtree();
- System.out.print(temp.getData() + "? ");
- String firstLeftLeaf = scanner.nextLine();
- if (firstLeftLeaf.equals("Yes") && temp.isLeaf()) {
- System.out.println("I guessed it!");
- System.out.print("Would you like to play again? ");
- String yesOrno = scanner.nextLine();
- if (yesOrno.equals("Yes"))
- temp = bt;
- else
- break;
- }
- else if (firstLeftLeaf.equals("No") && temp.isLeaf()) {
- System.out.print("What is your animal? ");
- String animal = scanner.nextLine();
- System.out.print("Provide a question that uniquely identifies your animal? ");
- String question = scanner.nextLine();
- BinaryTree<String> save = bt;
- temp = bt.getLeftSubtree();
- temp.setData(question);
- temp.setLeftSubtree(save);
- BinaryTree<String> animal2 = new BinaryTree<>(animal);
- temp.setRightSubtree(animal2);
- System.out.print("Would you like to play again? ");
- String yesOrno = scanner.nextLine();
- if (yesOrno.equals("Yes"))
- temp = bt;
- else
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement