Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import java.util.Scanner;
- public class GuessGame {
- String in = "Gives up!!";
- static Scanner input1 = new Scanner(System.in);
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- Node root= Node();
- while(true){
- root=PlayGame(root);
- }
- }
- public static Node PlayGame(Node n) {
- System.out.println(in);
- Scanner input = new Scanner(new File("result.txt"));
- Node n;
- if (n.isEmpty()) {
- System.out.print("I give up, what is it?");
- String resp = input1.next();
- n.setText(resp);
- return n; }
- else if (!n.getText())
- return guess(n);
- else ask(n);
- return n;
- }
- public ask(n) {
- System.out.print(n.text);
- if resp n.right=playGame(n.right);
- else
- n.left=playGame(n.left);
- }
- public guess(n) {
- System.out.println("is it a");
- String resp = input1.next();
- if (resp.endsWith("yes")
- return n;
- else System.out.println("I give up, what is it?");
- right=Node(resp);
- System.out.println("Please enter a question to differentiate between these two");
- question=Node(resp,right,n);
- return question;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement