Advertisement
Guest User

Untitled

a guest
Nov 21st, 2014
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. import java.io.File;
  2. import java.util.Scanner;
  3.  
  4.  
  5. public class GuessGame {
  6. String in = "Gives up!!";
  7. static Scanner input1 = new Scanner(System.in);
  8. public static void main(String[] args) {
  9. // TODO Auto-generated method stub
  10.  
  11.  
  12. Node root= Node();
  13. while(true){
  14. root=PlayGame(root);
  15. }
  16.  
  17. }
  18. public static Node PlayGame(Node n) {
  19. System.out.println(in);
  20. Scanner input = new Scanner(new File("result.txt"));
  21.  
  22. Node n;
  23. if (n.isEmpty()) {
  24. System.out.print("I give up, what is it?");
  25.  
  26. String resp = input1.next();
  27. n.setText(resp);
  28. return n; }
  29.  
  30. else if (!n.getText())
  31. return guess(n);
  32.  
  33. else ask(n);
  34. return n;
  35. }
  36. public ask(n) {
  37. System.out.print(n.text);
  38. if resp n.right=playGame(n.right);
  39.  
  40. else
  41. n.left=playGame(n.left);
  42.  
  43. }
  44.  
  45. public guess(n) {
  46. System.out.println("is it a");
  47. String resp = input1.next();
  48. if (resp.endsWith("yes")
  49.  
  50. return n;
  51. else System.out.println("I give up, what is it?");
  52. right=Node(resp);
  53. System.out.println("Please enter a question to differentiate between these two");
  54. question=Node(resp,right,n);
  55. return question;
  56. }
  57.  
  58.  
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement