Program: In this program, we run a do-while loop and display a menu for the user, take input from the user and display the output using switch case statements. The do-while loop ends when the user enters 0.
Code:
import java.util.Scanner; public class Loop { public static void main(String[] args) { //Create Scanner class instance Scanner scan = new Scanner(System.in); //Define variable for userinput int userInput; //Start the do-while loop do { //Display message System.out.println("Please select one of the following tasks to continue: "); System.out.println("1. Option 1 \n2. Option 2 \n3. Option 3 \n4. Option 4 \n5. Exit"); //Take user input from keyboard userInput = scan.nextInt(); //Switch case statement switch (userInput){ case 1: System.out.println("Do the option 1"); break; case 2: System.out.println("Do the option 2"); break; case 3: System.out.println("Do the option 3"); break; case 4: System.out.println("Do the option 4"); break; case 0: System.out.println("Terminate the program"); break; default: System.out.println("Invalid task"); break; } } //While loop condition while(userInput!=0); } }
Output:
java program QUESTION 2: 1. Write a do-while loop that asks the user to select a...
Write a Program that has a menu with a layout below, that asks the user if they want to: 1. Converts from feet and inches to meter and centimeters 2. Converts from meter and centimeters to feet and inches 3. Quit the program The program should continue as long as the user asks it to. The program will use a switch statement for the menu option selection. Either a do loo or a do-while loop can be used for the overall...
The purpose of this assignment is to get experience with an array, do while loop and read and write file operations. Your goal is to create a program that reads the exam.txt file with 10 scores. After that, the user can select from a 4 choice menu that handles the user’s choices as described in the details below. The program should display the menu until the user selects the menu option quit. The project requirements: It is an important part...
1. Create a String variable named menuChoice. 2. Display 3 options for your program. I recommend using 3 System.out.println statements and a 4th System.out.print to show "Enter your Selection:". This needs to be inside the do -- while loop. A. Deposit Cash. B. Withdraw Cash X. Exit Enter your Selection: 3. Prompt for the value menuChoice. 4. If menuChoice is "A", display "Do Deposit" and redisplay the menu. If menuChoice is "B", display "Do withdrawal" and redisplay the menu. If...
Write codes that will produce the screen as shown Firstly, the program prompts user to enter his name. Then it will display Hello <user name>. Next it prints out a menu which contains 5 options (1- add two integers, 2- add two strings, 3- compute factorial, 4- reverse a string, 5- quit program). Code all 5 tasks appropriately. When the task is completed (not including quitting program of course), the menu pops up again and asks user to try...
HELP IN JAVA: WHILE LOOP: Write a program that asks the user to enter a number of seconds. This number should be less than or equal to 32767 because that is the largest number pep8 can handle. Your program should then output the number of hours, minutes, and seconds on the planet of Crypton, where there are 64 seconds in a minute and 32 minutes in an hour.
Project 1, Program Design 1. Write a C program replace.c that asks the user to enter a three-digit integer and then replace each digit by the sum of that digit plus 6 modulus 10. If the integer entered is less than 100 or greater than 999, output an error message and abort the program. A sample input/output: Enter a three-digit number: 928 Output: 584 2. Write a C program convert.c that displays menus for converting length and calculates the result....
In java Write a program that asks the user to choose a selection (Enter 1 to convert from binary to decimal, 2 to convert from decimal to binary, 3 to convert binary to hexadecimal, 4 to convert hexadecimal to binary, 5 to convert decimal to hexadecimal, 6 to convert hexadecimal to decimal. Pls do it by creating classes and objects with get and set method.
Please make a JAVA program for the following using switch structures Write a program that simulates a simple Calculator program. The program will display menu choices to the user to Add, Subtract, Multiply and Divide. The program will prompt the user to make a selection from the choices and get their choice into the program. The program will use a nested if….else (selection control structure) to determine the user’s menu choice. Prompt the user to enter two numbers, perform the...
Programming Instructions:Using Java Object Oriented Principles, write a program which produces the code as indicated in the following specifications: Your program must be a console application that provides a user this exact menu:Please select one of the following:1: Add Client to Bank2: Display Clients in the Bank3: Set Bank Name4: Search for a Client5: Exit Enter your Selection: <keyboard input here> The menu must be displayed repeatedly until 5...
extra credit 1 Write a program that will display the following menu and prompt the user for a selection: A) Add two numbers B) Subtract two numbers C) Multiply two numbers D) Divide two numbers X) Exit program The program should: display a hello message before presenting the menu accept both lower-case and upper-case selections for each of the menu choices display an error message if an invalid selection was entered (e.g. user enters E) prompt user for two numbers...