In: Computer Science
Description Your program must start and keep dialog with the user. Please create the first prompt for the dialog. After that your program must accept the user’s response and echo it (output to screen) in upper case and adding the question mark at the end. The program must run endlessly until the user say “stop” in any combination of cases. Then you program must say “GOODBYE!” and quit. Example: HELLO, I AM THE PROGRAM Hi, I am Michael HI, I AM MICHAEL? Are you kidding? ARE YOU KIDDING?? I prefer to speak to somebody smarter I PREFER TO SPEAK TO SOMEBODY SMARTER? Stupid STUPID? You YOU? sToP! STOP!? stop GOODBYE!
Since, no programming language has been explicitly mentioned in the question, I am coding this in Java programming language. All the comments have been written in italics to differentiate from the main program.
import java.util.*;
import java.io.*;
import java.lang.*;
public class Dialog
{
public static void main(String[] args)
{
String text;
Scanner sc=new Scanner(System.in);
//Create a scanner object
System.out.println("HELLO I AM THE
PROGRAM"); //First prompt for the dialog. You can change it
according to your requirement
text=sc.nextLine(); //Taking
input for the user’s response
while(text.equalsIgnoreCase("stop")==false) //Until the user
enters stop (case insensitive), the program continues to echo
user's response
{
System.out.println(text.toUpperCase()+"?"); //Changing the
user's response to uppercase and adding question mark
text=sc.nextLine(); //Taking input for the user’s
response
}
System.out.println("GOODBYE!");
//When the user enters stop (case insesitive), the program
prints GOODBYE!
}
}
Adding the snapshot of the code output: