Simple ChatBot Application in java

     ChatBot is a simple AI application. Whenever user asks a question, it gives you the response. This chatbot is developed using java language.

How to create a simple Chatbot application in java?

First, get the input from the user. Check the input with the corresponding content and

display the output.

Steps to follow:

  • ·       Include the built-in package.
  • ·       Create a public class with a main() function.
  • ·       Read the input from the user.
  • ·       Call the function to get the response.
  • ·       Convert the user input into lowercase.
  • ·       Check the input with the keywords.
  • ·       If the keyword is found, it gives the output.
  • ·       Finally,when you give bye,the chatbot ends the process.

Program:

import java.util.Scanner;

public class ChatBotEg {

    public static void main(String[] args) {

        Scanner scanner1 = new Scanner(System.in);

        String userIn;

        System.out.println("Welcome to ChatBot world for memory storage. How can I help you  

        today?");

        while (true) {

            userIn = scanner1.nextLine();

            String response1 = getResponse(userIn);

            System.out.println(response1);

            if (userIn.equalsIgnoreCase("bye")) {

                break;

            }

        }

        scanner1.close();

        System.out.println("Thank you for using ChatBot World.Goodbye!");

    }

    public static String getResponse(String input) {

        input = input.toLowerCase();

        if (input.contains("hi") || input.contains("hello")) {

            return "Hello! Shall I help you?. ask me questions about memory";

        } else if(input.contains("what is a bit")) {

            return "bit is a binary digit";}

        else if(input.contains("nibble")) {

            return "Nibble is 4 bit binary digit";

        } else if(input.contains("byte")) {

            return "byte is a 8 bit binary digit";

        } else if(input.contains("kb")) {

            return "Kilobyte is 1024 bytes.It is represented as KB";

        } else if(input.contains("mb")) {

            return "Megabyte is 1024 kilobytes.It is represented as MB";

        } else if(input.contains("gb")) {

            return "Gigabyte is 1024 megabytes.It is represented as GB";

        } else if(input.contains("tb")) {

            return "Terabyte is 1024 Gigabytes.It is represented as TB";

        } else if(input.contains("pb")) {

            return "Petabyte is 1024 Terabytes.It is represented as PB";

        } else if(input.contains("eb")) {

            return "Exabyte is 1024 petabytes.It is represented as EB";

        } else if(input.contains("zb")) {

            return "Zettabyte is 1024 Exabytes.It is represented as ZB";

        } else if(input.contains("yb")) {

            return "Yottabyte is 1024 Zettabytes.It is represented as YB";

        }

        else {

            return "I'm not sure how to respond to that.";

        }

    }

}

Output:

C:\raji\blog>javac ChatBotEg.java

C:\raji\blog>java ChatBotEg

Welcome to ChatBot world for memory storage. How can I help you today?

hi

Hello! Shall I help you?. ask me questions about memory

byte

byte is a 8 bit binary digit

kb

Kilobyte is 1024 bytes.It is represented as KB

gb

Gigabyte is 1024 megabytes.It is represented as GB

tb

Terabyte is 1024 Gigabytes.It is represented as TB

zb

Zettabyte is 1024 Exabytes.It is represented as ZB

yb

Yottabyte is 1024 Zettabytes.It is represented as YB

bye

Thank you for using ChatBot World.Goodbye!

This is a simple Chatbot implemented in java. Keep coding!!!

No comments:

Post a Comment