Advertisement
irmantas_radavicius

Untitled

Feb 24th, 2022
747
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.55 KB | None | 0 0
  1. package ChatBot;
  2. import java.util.Scanner;
  3.  
  4. public class ChatBot {
  5.    
  6.     public static void main(String[] args) {
  7.         Scanner cin = new Scanner(System.in);
  8.         int ok=1,ind=0;
  9.         String me,bot;
  10.         bot="Hello!";
  11.         System.out.println(bot);
  12.         me=cin.nextLine();
  13.         while(ok==1) {
  14.                 switch(ind) {
  15.                 case 0: bot="I am Carl, who are you? ";  break;
  16.                 case 1: {
  17.                     String name="";
  18.                     for(int i=1;i<me.length()-1;i++){
  19.                         if(Character.isUpperCase(me.charAt(i))){
  20.                             {
  21.                                for(int j=i; j<me.length();j++) {
  22.                                    if(me.charAt(j)==' ' || me.charAt(j)=='.' )
  23.                                        break;
  24.                                    name+=me.charAt(j);
  25.                              
  26.                               }
  27.                         }
  28.                         }
  29.                     }
  30.                     bot="Nice to meet you," + name + ". How old are you?";
  31.                      break;
  32.                 }
  33.                 case 2:
  34.                 {   String age="";
  35.                     for(int i=0;i<me.length();i++){
  36.                          if(Character.isDigit(me.charAt(i)))
  37.                              age+=me.charAt(i);          
  38.                     }
  39.                     int age1= Integer.parseInt(age);
  40.                     bot="I am 20 years old.";
  41.                     if(age1==20)
  42.                         bot+=" Wow! We are the same age! ";
  43.                     else if (age1<20)  
  44.                         bot+="You are smaller than me.";
  45.                     else
  46.                         bot+="You are older than me.";
  47.                     bot+="\nSo, What are you doing? ";
  48.                     break;                 
  49.                 }
  50.                 case 3 :
  51.                 {
  52.                     if(me.indexOf("nothing")!=-1 ||me.indexOf("Nothing")!=-1 || me.indexOf("bored")!=-1)
  53.                         bot="I understand, you can read a book.";
  54.                     else
  55.                         bot="Nice.";
  56.                     if(me.indexOf("you")!=-1 || me.indexOf("?")!=-1)
  57.                         bot+=" I am just talking to you.";
  58.                     bot+="\nBy the way, Where are you from?";  
  59.                     break; 
  60.                 }
  61.                 case 4: bot="I like this place. I am from Lithuania. How is the weather there ?";  break;
  62.                 case 5:{
  63.                     if(me.indexOf("hot")!=-1 || me.indexOf("sunny")!=-1)
  64.                         bot="You should go for a walk. Don't miss a beautiful day.";
  65.                     else
  66.                         bot="So you're staying at home today, aren't you?";
  67.                     bot+="\nHere it snows.";
  68.                     break;
  69.                 }
  70.                 case 6:
  71.                     bot="Ok! I wish you a nice day! Bye!";
  72.                     ok=0;
  73.                     break;
  74.                }
  75.             System.out.println(bot);
  76.             me=cin.nextLine();
  77.             ind++;
  78.         }
  79.  
  80.    
  81.     }
  82. }
  83.  
  84.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement