Advertisement
Guest User

Untitled

a guest
Dec 6th, 2019
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.69 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.util.List;
  3. import java.util.ArrayList;
  4.  
  5. public class ChatInput
  6. {
  7. /*This is simulated "Chatbot" program that is very primative.
  8. *Use this as an example and template for making your own Chatbot.*/
  9. private static Scanner input = new Scanner(System.in);
  10. private static Scanner input2 = new Scanner(System.in);
  11. private static Scanner input3 = new Scanner(System.in);
  12. private static Scanner input4 = new Scanner(System.in);
  13. private static Scanner input5 = new Scanner(System.in);
  14. private static Scanner input6 = new Scanner(System.in);
  15. private static Scanner input7 = new Scanner(System.in);
  16. private static String response = "";
  17. private static String response2 = "";
  18. private static String response3 = "";
  19. private static String response4 = "";
  20. private static String response5 = "";
  21. private static int response6 = 0;
  22. private static String response7 = "";
  23. private static int index;
  24. private static int index2;
  25. private static List<String> riddleList = new ArrayList<String>();
  26. private static List<String> answerList = new ArrayList<String>();
  27. private static int guess;
  28.  
  29.  
  30.  
  31. public static void randomStuff ()
  32. { if(response2.indexOf("yes") >=0 || response2.indexOf("yea") >=0 || response2.indexOf("yeah") >=0)
  33. {
  34. System.out.println("Who is your best friend?");
  35. response3 = input3.nextLine();
  36. System.out.println("Tell me more about " + response3);
  37.  
  38.  
  39. }
  40. else if (response2.indexOf("games") >=0)
  41. {
  42. System.out.println("What kind of games do you like to play?");
  43. response3 = input3.nextLine();
  44. System.out.println("What else do you do for fun?");
  45. }
  46. else if (response2.indexOf("movies") >=0)
  47. {
  48. System.out.println("What is your favorite movie?");
  49. response3 = input3.nextLine();
  50. System.out.println("I like that movie too! My favorite is Good Will Hunting");
  51. }
  52. else if (response2.indexOf("play") >=0)
  53. {
  54. System.out.println("What sports do you play?");
  55. response3 = input3.nextLine();
  56. System.out.println("What is your favorite professional sport?");
  57. response4 = input4.nextLine();
  58. System.out.println("Who is your favorite player?");
  59. response5 = input5.nextLine();
  60. System.out.println("Mine too! We have a lot in common, great talking with you. Let's chat again soon!");
  61. }
  62. else if (response2.indexOf("shop") >=0)
  63. {
  64. System.out.println("I'm not a big fan of shopping but my finance likes to shop!");
  65. }
  66. else if (response2.indexOf("sleep") >=0)
  67. {
  68. System.out.println("Me too! Sleeping is very important, great for recovery of the mind and body!");
  69. System.out.println("How many hours of sleep do you get each night?");
  70. response6 = input6.nextInt();
  71. if (response6 <= 6)
  72. {
  73. System.out.println("That's not enough sleep!");
  74.  
  75. }
  76. else if (response6 == 6 || response6 ==7)
  77. {
  78. System.out.println("That's a decent amount but you should try to get 8 or more hours each night");
  79. }
  80. else if (response6 >= 8)
  81. {
  82. System.out.println("That's excellent, you must be well rested!");
  83. }
  84. else
  85. System.out.println("Did you enter a number?? i.e. 1-10??");
  86.  
  87. }
  88. else
  89. {
  90. System.out.println("Great let's talk some more! Tell me about your family.");
  91. }
  92.  
  93. }//ends method
  94.  
  95.  
  96. public static void getQuestion()
  97. {
  98.  
  99.  
  100. riddleList.add("What can you catch but not throw?");
  101. riddleList.add("The more you take, the more you leave behind. What am I?");
  102. riddleList.add("What belongs to you, but other people use it more than you?");
  103. riddleList.add("What has many keys, but can't even open a single door?");
  104. riddleList.add("What is more useful when it is broken?");
  105.  
  106. String question = riddleList.get(index);
  107. System.out.println(question);
  108.  
  109.  
  110. }
  111. public static void getAnswer()
  112. {
  113.  
  114. answerList.add("a cold");
  115. answerList.add("footsteps");
  116. answerList.add("your name");
  117. answerList.add("a piano");
  118. answerList.add("an egg");
  119.  
  120. String answer = answerList.get(index);
  121. System.out.println(answer);
  122. }
  123.  
  124.  
  125. public static void main (String[] args)
  126. {
  127. index = (int)(Math.random()*6);
  128. index2 = (int)(Math.random()*10);
  129. int guess = 3;
  130. /*Each input variable creates a line in the console that allows
  131. *the program to "scan" +it or be read.
  132. *Each response is then stored in a variable, many of which have been
  133. *named with some variation of response. */
  134. System.out.println("Please use all lowercase letter's in your responses.");
  135.  
  136.  
  137.  
  138.  
  139.  
  140. //The users response will be stored int the response variable
  141. System.out.println("Welcome, I'm Chatbot! What's your name?");
  142. response = input.nextLine();
  143. System.out.println("Hello, " + response + ", would you like to play a game?");
  144. response2 = input2.nextLine();
  145.  
  146. /*You can use as many complex conditionals as you like,
  147. *the more you use the more comprehensive you program might be.
  148. *Notice the complex conditional looks for the String no, bad, terrible, or sick.
  149. *If one or more of those words is found the "chatbot" will respond by saying "Why so negative..."*/
  150.  
  151. /*You can use nested conditionals and loops to make your chatbot more extensive */
  152. if (response2.indexOf("no") >=0 || response2.indexOf("no thank you") >=0 || response2.indexOf("nah") >=0)
  153. {
  154. System.out.println("Are you sure?") ;
  155. System.out.println("The game will be very fun!");
  156. response3 = input.nextLine();
  157. if (response3.indexOf("no") >=0 || response3.indexOf("no thank you") >=0 || response3.indexOf("yes") >=0)
  158. {
  159. System.out.println("Okay, have a good day " + response);
  160.  
  161. }
  162. }
  163. else if (response2.indexOf("yes") >=0 || response2.indexOf("yea") >=0 || response2.indexOf("yeah") >=0 || response2.indexOf("sure") >=0 || response2.indexOf("ok") >=0 || response2.indexOf("okay")>=0 || response2.indexOf("alright")>=0)
  164. {
  165. System.out.println("There are a few rules before we begin. You must follow them for our game to run as smoothly as possible.");
  166. System.out.println("Rule 1: Use all lowercase letters in your responses.");
  167. System.out.println("Rule 2: You have three guesses.");
  168. System.out.println("Rule 3: Have fun!!!.");
  169. System.out.println("Are you ready?");
  170. response3 = input2.nextLine();
  171.  
  172. if(response3.indexOf("yes") >=0 || response3.indexOf("yea") >=0 || response3.indexOf("yeah") >=0 || response3.indexOf("sure") >=0 || response3.indexOf("ok") >=0 || response3.indexOf("okay")>=0 || response3.indexOf("alright")>=0)
  173. {
  174. getQuestion();
  175. response3 = input2.nextLine();
  176. if(response3.equals(answerList.get(index)))
  177. {
  178. System.out.println("Correct!");
  179. }
  180. else
  181. {
  182. while(guess < 3)
  183. {
  184. if(guess == 2)
  185. {
  186. System.out.println("You have 2 guesses left.");
  187. }
  188. else if(guess == 1)
  189. {
  190. System.out.println("You have 1 guesses left.");
  191. }
  192. else
  193. {
  194. System.out.println("You lost AHAHHA");
  195. }
  196.  
  197. }
  198.  
  199.  
  200.  
  201.  
  202. }
  203. }
  204. }
  205. }
  206. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement