daily pastebin goal
5%
SHARE
TWEET

20 Questions

a guest Mar 19th, 2019 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. while(!temp.isLeaf()) {
  2.             System.out.print(temp.root + " (Y/N)? ");
  3.             String rootAnswer = scanner.nextLine();
  4.  
  5.             if(rootAnswer.equals("Y"))
  6.                 temp = temp.getRightSubtree();
  7.  
  8.             else if(rootAnswer.equals("N"))
  9.                 temp = temp.getLeftSubtree();
  10.  
  11.             else
  12.                 System.out.println("Please enter Y or N next time!");
  13.  
  14.         }
  15.  
  16.        
  17.         while(temp.isLeaf()) {
  18.             System.out.print(temp.getData() + " (Y/N)? ");
  19.             String firstGuess = scanner.next();
  20.  
  21.             if(firstGuess.equals("Y")) {
  22.                 System.out.println("I guessed it!");
  23.                 break;
  24.             }
  25.  
  26.  
  27.             else if(firstGuess.equals("N")) {
  28.                 Scanner animalGet = new Scanner(System.in);
  29.                 System.out.print("What is your animal? ");
  30.                 String animal = animalGet.next();
  31.  
  32.                 Scanner questionGet = new Scanner(System.in);
  33.                 System.out.print("Provide a question that uniquely identifies your animal? ");
  34.                 String question = questionGet.nextLine();
  35.  
  36.                 String save = temp.getData();
  37.                 temp.setData(question);
  38.                 temp.setRightSubtree(new BinaryTree<>(animal));
  39.                 temp.setLeftSubtree(new BinaryTree<>(save));
  40.             }
  41.            
  42.             else
  43.                 System.out.print("Please enter Y or N next time!");
  44.         }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top