Tuesday, November 6, 2018

How to make a Java based simple chatbot


Hey guys,

Welcome to treaktech. In this tutorial i’m gonna show you how to make a Java based simple chatbot.
What all you need for making this chatbot :
  • JDK
  • A Java IDE (I used Bluej and I also suggest you to use it for this program.)
Now first of all create a class named “Chatty” on your IDE.
Then paste this code
//# Chatty Java.
//This is one of the most simplest java based chatbots in the world.
//NEWS FOR THE NEXT UPDATE!! :N/A
//Developed on Bluej.
//# A code by Briyan Paul.
//# www.treaktech.blogspot.com
import java.util.*;
public class Chatty
{
    public static void main (String[]args)
    {
        Scanner b=new Scanner(System.in);
         System.out.println ("//   // //   // //  // //   // // // //  //");
         System.out.println ("  //  h   //   e  //  l  //  l  //  o  //");
         System.out.println ("//   // //   // //   // //  // // // // //");
         System.out.println("Welcome to Chatty Java");
         System.out.println("VERSION 2.0"); //New feature:Added Exit statement.Made it a stable complete program, and also "what is your name" statement. 
        
         while (true)
    {
        String a=b.nextLine();
        
        switch (a)
        {
case ("hello") :       //greetings
System.out.println ("hi");
break;
case ("hi") :
System.out.println("Hello");
break;
case ("hii") :
System.out.println("hello");
break;
case ("how are you") :  //talking statements
System.out.println ("fine");
break;
case ("good huh") :
System.out.println("good yeah");
break;
case ("howdy") :
System.out.println("Good :)");
break;
case ("what is your name") :
String name;
System.out.println("Chatty");
System.out.println("What about you ?");
name=b.nextLine();
System.out.println("Ohh "+name);
System.out.println("Nice name");
break;
case ("add") :    //calculations
int no$,no$$,ans$=0;
System.out.println("Enter two no's to add");
no$=b.nextInt();
no$$=b.nextInt();
ans$=no$+no$$;
System.out.println("The answer is :" +ans$);
break;
case ("subtract"):
int dif$,dif$$,ansdif=0;
System.out.println("Enter two no's to subtract");
dif$=b.nextInt();
dif$$=b.nextInt();
ansdif=dif$-dif$$;
System.out.println("The ans is :" +ansdif);
break;
case ("multiply") :
int mul$,mul$$,mulans=0;
System.out.println("Enter two no's to multiply");
mul$=b.nextInt();
mul$$=b.nextInt();
mulans=mul$*mul$$;
System.out.println("The answer is :"+mulans);
break;
case ("divide") :
int div$,div$$,divans;
System.out.println("Enter two no's to divide");
div$=b.nextInt();
div$$=b.nextInt();
divans=div$/div$$;
System.out.println("The answer is :"+divans);
break;
case ("you are great") :  //emotions
System.out.println("AWW thank you. You are great too");
break; 
case("great") :
System.out.println(":)");
break;
case ("thanks") :
System.out.println("Welcome");
break;
case ("tell me a joke") : //laughing statements
System.out.println("My dog used to chase people with their bikes");
break;
case ("hahaha") :
System.out.println("LoL");
break;
case ("lol") :
System.out.println("laugh out loud");
break;
case ("bye") :    //Farewell statements
System.out.println("Byee");
System.out.println("See ya later");
System.exit(1);
break;
case ("bubye") :
System.out.println("bye bye");
System.exit(1);
break;
case ("tata") :
System.out.println ("bubyeee");
System.exit(1);
break;
case ("see ya") :
System.out.println("Bye.Take care");
System.exit(1);
break;
case ("exit") :
System.out.println("Bye");
System.exit(1);
break;
}
}
}
}
Now compile and save your program.
On some computers due to some character encoding issues you will  find some errors.So in order to correct it you should do like this:
In my pc when I copy this code and paste this to my bluej ide it will show error like this
So what you have to do is
copy this quotation mark   and perform find and repalce it with you keyboards quatation mark ( “).
Then again select the other end’s quotation mark  and do the same as above.The error will be gone.
Yeah. You have successfully made a chatbot.


















Please don’t forget to send the code that you have edited to my email. www.briyanpaulpb@gmail.com
I will post it and give you the credit for the part that you made.
You can put your doubts on the  comment box.  I will try to give the reply as fast as I can.


Also checkout : http://treakrobotics.000webhostapp.com/

4 comments:

  1. When your website or blog goes live for the first time, it is exciting. That is until you realize no one but you and your. Chatbot for beginners

    ReplyDelete
  2. I have read a few of the articles on your website now, and I really like your style of blogging. I added it to my favorites blog site list and will be checking back soon. Please check out my site as well and let me know what you think. qualified leads

    ReplyDelete
  3. When your website or blog goes live for the first time, it is exciting. That is until you realize no one but you and your. qualified leads

    ReplyDelete