QuestionQuestion

Write a program ChatBot.java, where the user inputs a one-line sentence and the computer responds accordingly.

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 PreviewSolution 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) == ' ')...
$7.00 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats