Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ChatBot;
- import java.util.Scanner;
- public class ChatBot {
- public static void main(String[] args) {
- Scanner cin = new Scanner(System.in);
- int ok=1,ind=0;
- String me,bot;
- bot="Hello!";
- System.out.println(bot);
- me=cin.nextLine();
- while(ok==1) {
- switch(ind) {
- case 0: bot="I am Carl, who are you? "; break;
- case 1: {
- String name="";
- for(int i=1;i<me.length()-1;i++){
- if(Character.isUpperCase(me.charAt(i))){
- {
- for(int j=i; j<me.length();j++) {
- if(me.charAt(j)==' ' || me.charAt(j)=='.' )
- break;
- name+=me.charAt(j);
- }
- }
- }
- }
- bot="Nice to meet you," + name + ". How old are you?";
- break;
- }
- case 2:
- { String age="";
- for(int i=0;i<me.length();i++){
- if(Character.isDigit(me.charAt(i)))
- age+=me.charAt(i);
- }
- int age1= Integer.parseInt(age);
- bot="I am 20 years old.";
- if(age1==20)
- bot+=" Wow! We are the same age! ";
- else if (age1<20)
- bot+="You are smaller than me.";
- else
- bot+="You are older than me.";
- bot+="\nSo, What are you doing? ";
- break;
- }
- case 3 :
- {
- if(me.indexOf("nothing")!=-1 ||me.indexOf("Nothing")!=-1 || me.indexOf("bored")!=-1)
- bot="I understand, you can read a book.";
- else
- bot="Nice.";
- if(me.indexOf("you")!=-1 || me.indexOf("?")!=-1)
- bot+=" I am just talking to you.";
- bot+="\nBy the way, Where are you from?";
- break;
- }
- case 4: bot="I like this place. I am from Lithuania. How is the weather there ?"; break;
- case 5:{
- if(me.indexOf("hot")!=-1 || me.indexOf("sunny")!=-1)
- bot="You should go for a walk. Don't miss a beautiful day.";
- else
- bot="So you're staying at home today, aren't you?";
- bot+="\nHere it snows.";
- break;
- }
- case 6:
- bot="Ok! I wish you a nice day! Bye!";
- ok=0;
- break;
- }
- System.out.println(bot);
- me=cin.nextLine();
- ind++;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement