Question

In: Computer Science

Using the provided code (found here), write a program using the main method where the user...

Using the provided code (found here), write a program using the main method where the user enters Strings and the program echoes these strings to the console until the user enters “quit”. When user quits the program should print out, “Goodbye”. You may assume that the case is ignored when the user enters, “quit”, so “quit”, “QUIT”, “Quit”,“qUiT”, etc. are all acceptable ways to end the program. The results should be printed out to the console in the following format:

<<Input00>>

“Echo: ”<<Input00>>

<<Input01>>

“Echo: ”<<Input01>>

“Quit”

“Goodbye”

Values denoted in “<< >>” represent variable values, and strings in quotations denote literal values (make sure to follow spelling, capitalization, punctuation, and spacing exactly).

Solution Tests:

  • Does the solution compile?
  • Does the solution have your name in the comments?
  • Does the solution have a high-level solution description (150-300 words) in the comments?
  • If the user enters the following input sequence <“Hello!”, “Greetings!”, “Salutations!”, “QUIT”>, then does the program print out:

Echo: Hello!

Echo: Greetings!

Echo: Salutations!

Goodbye

(This only shows the program’s output and has omitted the greeting message and the user’s input in the console)

  • If the user enters the following input sequence <“1”, “2”, “3”, “4”, “5”, “quit”>, then does the program print out:

Echo: 1

Echo: 2

Echo: 3

Echo: 4

Echo: 5

Goodbye

(This only shows the program’s output and has omitted the greeting message and the user’s input in the console)

  • If the user enters the following input sequence <“STOP”, “end”, “Halt”, “qUiT”>, then does the program print out:

Echo: STOP

Echo: end

Echo: Halt

Goodbye

(This only shows the program’s output and has omitted the greeting message and the user’s input in the console)

/Do not alter-----------------------------------------------------------------------
import java.util.Scanner;
public class Question02 {

        public static void main(String[] args) {
                Scanner keyboard;
                if(args == null || args.length == 0)
                {
                        keyboard = new Scanner(System.in);
                        System.out.println("Welcome to the Echo Program! I'll echo whatever is said until you enter \"quit\"");
                }
                else
                {
                        keyboard = new Scanner(args[0]);
                }
//-----------------------------------------------------------------------------------
                //Write your solution here

                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
        }//Do not alter this
//Space for other methods if necessary-----------------------------------------------
        //Write those here if necessary
        
//-----------------------------------------------------------------------------------
}//Do not alter this

/*Solution Description
 * 
 */

Solutions

Expert Solution


import java.util.Scanner;

public class Question2 {

        /*
         * @author name
         */
        public static void main(String[] args) {
                   Scanner keyboard;
           if(args == null || args.length == 0)
           {
                   keyboard = new Scanner(System.in);
                   System.out.println("Welcome to the Echo Program! I'll echo whatever is said until you enter \"quit\"");
           }
           else
           {
                   keyboard= new Scanner(args[0]);
           }
           String s=null;
           while(true) {
                   s=keyboard.next();
                   if(s.equalsIgnoreCase("Quit")) {
                           System.out.println("Goodbye");
                           break;
                           }
                   System.out.println("Echo:"+s);
           }
         }//Do not alter this
        //Space for other methods if necessary-----------------------------------------------
                //Write those here if necessary
                
        //-----------------------------------------------------------------------------------
}//Do not alter this

        /*Solution Description
         * 
         * In this code I just take a while loop while always true inside it
         * it will make your loop running continuously and you can break it anytime you want
         * SO i put base condition i.e. if I enter quit then it'll break from the loop else
         * it'll print the echo the same string which you entered.
         */

Yes the above code is compiled I'll attach the screenshot of output with the code.

I hope you liked the solution If you do so then support us by pressing upvote button.


Related Solutions

write a program using the main method where the user enters a number greater than 0,...
write a program using the main method where the user enters a number greater than 0, and the program prints out a set of stairs. The stairs consist of 3 boxes stacked on top of each other where the length and width of the first box is the number, the length and width of the second box is the number plus 1, and the length and width of the third box is the number plus 2. The stairs should be...
write a program using the main method where it searches through an array of positive, non-zero...
write a program using the main method where it searches through an array of positive, non-zero integer values and prints out the maximum even and odd values. The program should use the array provided in the code, and you may assume that it has already been populated with values. The results should be printed out to the console in the following format: “Max Even: ”<<max even value>> “Max Odd: ”<<max odd value>> Values denoted in “<< >>” represent variable values,...
Using the code below from “LStack.h” file, write the code for a main program that takes...
Using the code below from “LStack.h” file, write the code for a main program that takes as input an arithmetic expression. The program outputs whether the expression contains matching grouping symbols. For example, the arithmetic expressions { 25 + ( 3 – 6 ) * 8 } and 7 + 8 * 2 contains matching grouping symbols. However, the expression 5 + { ( 13 + 7 ) / 8 - 2 * 9 does not contain matching grouping symbols....
Write a Java test program, all the code should be in a single main method, that...
Write a Java test program, all the code should be in a single main method, that prompts the user for a single character. Display a message indicating if the character is a letter (a..z or A..Z), a digit (0..9), or other. Java's Scanner class does not have a nextChar method. You can use next() or nextLine() to read the character entered by the user, but it is returned to you as a String. Since we are only interested in the...
Write a program that contains a main method and another method named userName. The main method...
Write a program that contains a main method and another method named userName. The main method should prompt the user to enter a full name. The userName method takes the full name as an argument and prints the name in reverse order and returns the number of characters in the name. See Sample Output (input shown in blue). Sample Output Please enter your FULL name Billy Joe McCallister Here is the name Billy Joe McCallister in reverse: retsillaCcM eoJ ylliB...
This needs to be a python3 code Write a program that prompts the user like this:...
This needs to be a python3 code Write a program that prompts the user like this: “Currency to convert to U.S. dollars: e = Euros, c= Chinese Yuan, r = Indian Rupees, b = Bitcoin: ”. Then depending on which letter the user enters, the program displays “Amount of Euros/Yuan/Rupees/Bitcoin to convert: ”. (Note: the second prompt should only name the one currency the user asked to convert, not all four currencies.) After the user enters the amount, the program...
Using the pseudocode found below, write only the actual (C++) code for this program. Include all...
Using the pseudocode found below, write only the actual (C++) code for this program. Include all libraries. Specification: Write a program that will repeatedly ask the user for quiz grades in the range from 0 to 20. Any negative value will act as a sentinel. When the sentinel is entered compute the average of the grades entered. Design: Constants None Variables float grade float total = 0 int count = 0 float average ------- Inital Algorithm Repeatedly ask user for...
Please write the code JAVA Write a program that allows the user to enter the last...
Please write the code JAVA Write a program that allows the user to enter the last names of five candidates in a local election and the number of votes received by each candidate. The program should then output each candidate’s name, the number of votes received, and the percentage of the total votes received by the candidate. Your program should also output the winner of the election. A sample output is: Candidate      Votes Received                                % of Total Votes...
*Please write code in C++* Write a program to verify the validity of the user entered...
*Please write code in C++* Write a program to verify the validity of the user entered email address.   if email is valid : output the stating that given email is valid. ex: "The email [email protected] is valid" else : output the statement that the email is invalid and list all the violations ex:  "The email sarahwinchester.com is invalid" * @ symbol * Missing Domain name The program should keep validating emails until user enter 'q' Upload your source code. ex: main.cpp
using Visual Studio write a code containing a main() program that implements the coin change state...
using Visual Studio write a code containing a main() program that implements the coin change state machine in C++ according to the guidance given in Translating a state machine to C++ Test your code using prices 1 and 91 cents, and assume change is calculated from a dollar bill. Copy and paste your console output to a text editor and save the result in a single file named console.txt. Upload your exercise081.cpp and console.txt files to Canvas.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT