Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- while(!temp.isLeaf()) {
- System.out.print(temp.root + " (Y/N)? ");
- String rootAnswer = scanner.nextLine();
- if(rootAnswer.equals("Y"))
- temp = temp.getRightSubtree();
- else if(rootAnswer.equals("N"))
- temp = temp.getLeftSubtree();
- else
- System.out.println("Please enter Y or N next time!");
- }
- while(temp.isLeaf()) {
- System.out.print(temp.getData() + " (Y/N)? ");
- String firstGuess = scanner.next();
- if(firstGuess.equals("Y")) {
- System.out.println("I guessed it!");
- break;
- }
- else if(firstGuess.equals("N")) {
- Scanner animalGet = new Scanner(System.in);
- System.out.print("What is your animal? ");
- String animal = animalGet.next();
- Scanner questionGet = new Scanner(System.in);
- System.out.print("Provide a question that uniquely identifies your animal? ");
- String question = questionGet.nextLine();
- String save = temp.getData();
- temp.setData(question);
- temp.setRightSubtree(new BinaryTree<>(animal));
- temp.setLeftSubtree(new BinaryTree<>(save));
- }
- else
- System.out.print("Please enter Y or N next time!");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement