Answered step by step
Verified Expert Solution
Question
1 Approved Answer
update below code (Currency conversion program) to add loop. (Implement if/else ladder for menu control) Please tell me how to add loop(while) into the code
update below code (Currency conversion program) to add loop. (Implement if/else ladder for menu control)
Please tell me how to add loop(while) into the code
1) If the user enters an invalid input the program loop back and allow the user to re-enter input until user input is valid
2) if the user input in the menu is invalid allow the user to re-enter input until user input is valid
*********************************************************************
- User Input dollar amount
- verify dollar amount
- open menu
- receive user menu selection
- output if menu is correct
- loopback to allow the user to make menu until correct
********************************************************************
import java.util.*; public class CurrencyConversion_loop { public static void main(String arg[]) { //Creates an object of Scanner Scanner sc = new Scanner(System.in); System.out.println("Enter 1. Euro Conversion"); System.out.println("Enter 2. Yen Conversion"); System.out.println("Enter 3. Peso Conversion"); System.out.println("Enter 4. Bitcoin Conversion"); System.out.println("Enter 5. All Conversion"); //takes selection's numebr from user System.out.println("Select the number: "); int datal sc.nextInt(); // takes input from user, the funds in dollar System.out.println("Enter funds in dolloar"); double dollars = sc.nextDouble(); double euro = dollars*0.92; double yen dollars*126.65; double peso dollars 19.97; double bitcoin dollars*0.000025; //Varifying the value that user entered. if(datal 1){ } " System.out.println(dollars + "dollars = " + euro + EUROS"); else if(data1 == 2){ } System.out.println(dollars + "dollars = else if(data1 == 3) { } System.out.println(dollars + "dollars = else if(data1 == 4){ } System.out.println(dollars + "dollars = else if(data1 == 5){ System.out.println(dollars + "dollars = System.out.println(dollars + "dollars = System.out.println(dollars + "dollars = System.out.println(dollars + "dollars = " " + yen + YENS"); " + peso + PESOS"); + bitcoin + " BTCS"); " + euro + EUROS"); + yen + "YENS"); + peso + " PESOS"); + bitcoin + " BTCS"); } else { System.out.println("Invalid Input"); sc.close(); } } 3
Step by Step Solution
There are 3 Steps involved in it
Step: 1
To add a loop to the currency conversion program and implement menu control using an ifelse ladder y...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started