I have the following JAVA Conversion Program given to me, and need to do Steps 1 through 4. Comments are marked by //: import java.util.Scanner;
I have the following JAVA "Conversion" Program given to me, and need to do Steps 1 through 4. Comments are marked by //:
import java.util.Scanner; import java.text.DecimalFormat; /**Chapter 5 Programming Challenge 8 - Conversion Program*/ public class ConversionProgram{ public static void main(String[] args){ String input; // To hold keyboard input int selection; // Menu selection double distance; // Distance in meters // Create a Scanner object for keyboard input. Scanner keyboard = new Scanner(System.in); // Get a distance. System.out.print("Enter a distance in meters: "); distance = keyboard.nextDouble(); // Display the menu and process the user's // selection until 4 is selected. do{ // Display the menu. menu(); // Get the user's selection. System.out.print(" Enter your choice: "); selection = keyboard.nextInt(); // Validate the user's selection. while (selection < 1 || selection > 4){ System.out.print("Invalid selection. Enter your choice: "); selection = keyboard.nextInt();}
//STEP 4: Process the user's selection
//for example, if(selection==1) showshowKilometers(distance)
System.out.println();} while (selection != 4);} /**The menu method displays the program's menu.*/ public static void menu(){ System.out.println("1. Convert to kilometers"); System.out.println("2. Convert to inches"); System.out.println("3. Convert to feet"); System.out.println("4. Quit the program");} /**STEP 1: Define showKilometers method that displays the kilometers that are equivalent to a specified number of meters. It takes one parameter: meters */ /**STEP 2: Define showInches method that displays the inches that are equivalent to a specified number of meters. It takes one parameter: meters */ /** STEP 3: Define showFeet method that displays the feet that are equivalent to a specified number of meters. It takes one parameter: meters */ }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
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