irmantas_radavicius

Untitled

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