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....
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 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...
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.
Write a program in Matlab where the program plays a hot and cold game. The user...
Write a program in Matlab where the program plays a hot and cold game. The user answers two inputs: x=input('what is the x location of the object?') y=input('what is the y location of the object?') You write the program so that the computer plays the game. Pick a starting point. Program Calculates the distance to the object. Program picks another point, calculates the distance to the object. Program knows its at the right spot when the distance is less than...
Write a program where a user of this program will play a game in which he/she...
Write a program where a user of this program will play a game in which he/she needs to guess a target number, which is a number that the program has randomly picked in the range that the user chooses. The program will repeatedly prompt for the guessed number and provide a clue whether the guessed number is bigger or smaller than the target number, until the guessed number equals the target number.
In the space provided below write a C++ program that asks the user to enter their...
In the space provided below write a C++ program that asks the user to enter their quarterly earnings for the past two years stores the data in a 2-dimensional array. The program then computes both the annual earnings as well as the total earning and prints the results along with the 2-dimensional array on screen as well as onto a file.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT