Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class ChatterBot {
  4. private static Scanner name;
  5. private static Scanner reply;
  6.  
  7. public static void main(String args[]) {
  8. // keywords that user will call upon
  9. String kWork = "work";
  10. String kSchool = "school";
  11. String kUni = "uni";
  12. String kUniversity = "university";
  13. String kSleepy = "sleepy";
  14. String kHungry = "hungry";
  15. String kNothing = "nothing";
  16. String kBored = "bored";
  17. String kHomework = "homework";
  18. String kAssignment = "assignment";
  19. // Array for keywords
  20. String[] Keyword = {"work","school","uni","university","sleepy","hungry","nothing","bored","homework",
  21. "assignment"};
  22.  
  23. System.out.println("Hi!");
  24. System.out.println("What's your name?");
  25. String Name;
  26. name = new Scanner(System.in);
  27. Name = name.nextLine();
  28. System.out.println("Hello, " + Name + "!");
  29. System.out.println("What would you like to talk about?");
  30. reply = new Scanner(System.in);
  31. String Reply = reply.nextLine();
  32.  
  33. // Split user reply into array
  34. String[] rsplit = Reply.split("\\s+");
  35. int i = 0;
  36. while (i < rsplit.length)
  37. {
  38. String userWord = rsplit[i];
  39.  
  40. System.out.println(userWord);
  41.  
  42. for (int j=0; j<Keyword.length; j++)
  43. {
  44. System.out.println(Keyword[j]);
  45.  
  46. if (userWord == Keyword[j])
  47. {
  48. if(Keyword[j] == "work")
  49. {
  50. System.out.println("How was Work?");
  51.  
  52. }
  53.  
  54. }
  55. }
  56. }
  57. }
  58. }
  59.  
  60. // str = "Hello I'm your String";
  61. // String[] splited = str.split("\\s+");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement