Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Create a basic chat bot without using a scanner. All input will come from the command line. If the user entered nothing at the command
Create a basic chat bot without using a scanner. All input will come from the command line.
If the user entered nothing at the command line, show Nothing to say?
If the user entered some variation of how are you today? show Fine, but could use some more power. As long as the input has the word "are" before the word "you", print this message. Make your program smart enough to accept variations of these words see output
If the user entered some variation of what is your favorite something? Display something? Im only interested in transistors.
In all other cases, show I didn't understand that. I can't pass all the test cases with the codes that I have.
Test Case
Passed!
Nothing to say?
Test Case
Passed!
Command Line arguments:
how are you today?
Fine, but could use some more power.
Test Case
Passed!
Command Line arguments:
how ARE yOU today?!?!
Fine, but could use some more power.
Test Case
Passed!
Command Line arguments:
You are not funny.
I didn't understand that.
Test Case
Passed!
Command Line arguments:
YOU ARE NOT FUNNY!
I didn't understand that.
Test Case
Passed!
Command Line arguments:
how are we able to make you happy?
Fine, but could use some more power.
Test Case
Passed!
Command Line arguments:
how are yYOu today
Fine, but could use some more power.
Test Case
Passed!
Command Line arguments:
how are how are we doing and you?
Fine, but could use some more power.
Test Case
Failed
Show what's missing
Command Line arguments:
what is your favorite cookie?
I didn't understand that.
Test Case
Passed!
Command Line arguments:
do you like cars?
I didn't understand that.
Test Case
Failed
Show what's missing
Command Line arguments:
what is your favorite car?
I didn't understand that.
Test Case
Failed
Show what's missing
Command Line arguments:
what favorite food?
I didn't understand that.
Test Case
Failed
Show what's missing
Command Line arguments:
what do I have to say to FIGURE OUT your FAVORITE soda?
I didn't understand that.
Test Case
Passed!
Command Line arguments:
i give up
public static void mainString args
checking whether user entered anything in command line or not
ifargslength
System.out.printlnNothing to say?";
else
String input ;
forString data: args
input input data ; appending all words of command line in a string
input input.toLowerCase; changing whole string in lowercase to make it caseinsensitive
int indexOfAre input.indexOfare; getting the index of word "are"
int indexOfYou input.indexOfyou; getting the index of word "you"
int indexOfFavourite input.indexOffavourite; getting the index of word "favourite"
checking if are is present before you or not if true then index of are is smaller than index of you
if indexOfAre && indexOfYou && indexOfAre indexOfYou
System.out.printlnFine but could use some more power.";
if string contains word favourite or not
else ifindexOfFavourite
getting the index of space after the word favourite
int spaceIndex input.indexOf indexOfFavourite;
getting the index of question mark
int qmIndex input.indexOf spaceIndex;
getting string between space and question mark after the word favourite
String str input.substringspaceIndexqmIndex;
System.out.printlnstrtrim Im only interested in transistors.";
else
System.out.printlnI didn't understand that.";
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started