Question

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 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) == ' ')...

This is only a preview of the solution. Please use the purchase button to see the entire solution

Related Homework Solutions

Matrix Problem in Java
Homework Solution
$13.00
Java
Programming
Coding
Computer Science
Matrix
Diagonals
Input File
Output File
Integers
Loops
Conditions
Statements
Swapping Numbers
Random Values
Variables
LinkedList in Java
Homework Solution
$30.00
Java
Programming
Computer Science
LinkedList
Methods
Variables
Statements
Players
Game Results
Client Code
List Head
Positions
Nodes
Personal Name List in Java
Homework Solution
$8.00
Java
Programming
Computer Science
Codes
Algorithms
Personal Name List
Records
Errors
Arrays
Items
Variables
Statements
Characters
Moving Elements
Input
Output
Java Programming Assignment
Homework Solution
$20.00
Java Test Application
Java Programming
Program
3-D Geometric Shape
Java Class
Constructor
Get help from a qualified tutor
Live Chats