Question
Specification:
The computer should continuously ask and respond to questions according to the following rules:
If the sentence ends with a question mark (?) and has an even number of spaces in the sentence, then respond with "yes" (note: 0 is an even number)
If the sentence ends with a question mark (?) and has an odd number of spaces in the sentence, then respond with "no".
If the sentence ends with an exclamation mark, then respond with "Wow!"
If the user enters "quit", then the program exits
In any other case, respond with:
You always say "<user input>"
Make sure the print out includes the quotation marks
Example Dialog:
Hello! Say something to me!
Are you the greatest?
no
Hello! Say something to me!
Are you the greatest robot?
yes
Hello! Say something to me!
yay!
Wow!
Hello! Say something to me!
I can't find my burrito
You always say "I can't find my burrito"
Solution Preview
This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.
import java.util.Scanner;public class ChatBox {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner keyboard = new Scanner(System.in);
String talk1;
while(true)
{
System.out.println("Hello! Say something to me!");
talk1 = keyboard.nextLine();
if(talk1.toLowerCase().compareTo("quit") == 0)
break;
if (talk1.endsWith("?")){
int spaceCount = 0;
for(int i = 0; i < talk1.length(); i++)
if(talk1.charAt(i) == ' ')...