Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class ChatterBot {
- private static Scanner name;
- private static Scanner reply;
- public static void main(String args[]) {
- // keywords that user will call upon
- String kWork = "work";
- String kSchool = "school";
- String kUni = "uni";
- String kUniversity = "university";
- String kSleepy = "sleepy";
- String kHungry = "hungry";
- String kNothing = "nothing";
- String kBored = "bored";
- String kHomework = "homework";
- String kAssignment = "assignment";
- // Array for keywords
- String[] Keyword = {"work","school","uni","university","sleepy","hungry","nothing","bored","homework",
- "assignment"};
- System.out.println("Hi!");
- System.out.println("What's your name?");
- String Name;
- name = new Scanner(System.in);
- Name = name.nextLine();
- System.out.println("Hello, " + Name + "!");
- System.out.println("What would you like to talk about?");
- reply = new Scanner(System.in);
- String Reply = reply.nextLine();
- // Split user reply into array
- String[] rsplit = Reply.split("\\s+");
- int i = 0;
- while (i < rsplit.length)
- {
- String userWord = rsplit[i];
- System.out.println(userWord);
- for (int j=0; j<Keyword.length; j++)
- {
- System.out.println(Keyword[j]);
- if (userWord == Keyword[j])
- {
- if(Keyword[j] == "work")
- {
- System.out.println("How was Work?");
- }
- }
- }
- }
- }
- }
- // str = "Hello I'm your String";
- // String[] splited = str.split("\\s+");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement