Question: Write a program for JAVA that will behave similarly to the chatbot , except the chatbots responses will no longer be random they will be
Write a program for JAVA that will behave similarly to the chatbot , except the chatbots responses will no longer be random they will be smart and somewhat more realistic. For example, if the user says something with the word father or mother, the chatbot could respond with Oh! What about your parents?. Or if the user says something about their brother or sister, it could say I have a sister. Her name is Siri. Perhaps the user hits enter without typing anything at all; the chatbot could ask Im sorry, I didnt hear anything. What did you say?
Add these Advanced Responses:
If the user writes I want apples. The responses should be Why do you want apples?
First, find whether or not the string the user entered contains want. If so, find the position of want and create a substring using that position to get the word after it (apples in this case) have this word saved in a new string.
Next, concatenate and use String methods to make a new String that saves the chatbots response, similar to the one shown above: Why do you want apples?, where apples is whatever word the user typed in originally.
Another example: The user types in I want potatoes. So the chatbots response is Why do you want potatoes?
If the user writes I want to buy a gaming computer the response should be Would you be happy if you had a gaming computer? Use the same technique as the steps above describe, but instead of having to check for want, here you will check for want to buy.
Notice that since want to buy still contains want (from Step 1), you will have to be more careful so that multiple responses dont appear. How would you make it so that only one chatbot response is shown, rather than both? Think about the if else statement and how it is structured with levels if the first condition comes out to be true, the rest are ignored.
If the user enters I like to bake cheesecakes. The response should be Why do you like to bake cheesecakes? Look at the pattern and think about the steps you took in the previous chatbot responses. What substring would you check for, and what substring would you save to create this response?
Make a method called getRespone() that will determine what string the chatbot will use to respond to the user. The method body will be the code you wrote for the steps above. In addition to this, what will be the required parameter(s) and return type?
What is the divide and conquer
strategy, as discussed in the textbook?
At the end of this method, include a pool of 5 responses that can be
randomly chosen if none of the other criteria match what the user has entered (i.e. if the chatbot cannot use any of the responses you created). For example, one of these could be I dont understand what youre saying. Can you reword that?
Make sure to include proper input and output back in the main method, as well as looping, so that the user can try to hold a conversation with your new chatbot.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
