Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that asks the user to enter a distance in meters. the program wi

ID: 3633320 • Letter: W

Question

Write a program that asks the user to enter a distance in meters. the program will then present the following menu of selections:
1. Converto to kilometers
2. Convert to inches
3. Convert to feet
4. Quit the program

The program will convert the distance to km, in, ft depending on the user's selection.

(for each conversion directions)
Write a void method name show kilometers which accepts the number of meters as an agrument. The method should display the argument converted to kilometers. Convert the meters to kilometers using the following forumla:
kilometers = meters * .001
inches =meters * 39.37
feet =meters * 3.281

Write a void method named menu that displays the menu of selections. This method should not accept any arguments. Invalid inputs should be respond with an error.
No negative numbers should be accepted.

Explanation / Answer

import java.util.Scanner;
import java.text.DecimalFormat;
public class conveter
{
public static void main(String[] args)
{

int selection; // Menu selection
double distance; // Distance in meters
Scanner keyboard = new Scanner(System.in);
do
{
System.out.print("Enter a positive distance in meters: ");
distance = keyboard.nextDouble();
}while(distance <= 0);
do
{

menu();

System.out.print(" Enter your choice: ");
selection = keyboard.nextInt();

while (selection < 1 || selection > 4)
{
System.out.print("Invalid selection. Enter your choice: ");
selection = keyboard.nextInt();
}

switch (selection)
{
case 1 : metersToKilometers(distance);
break;
case 2 : metersToInches(distance);
break;
case 3 : metersToFeet(distance);
break;
case 4 : System.out.println("Bye!");
}
System.out.println();
} while (selection != 4);
}

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");
}
public static void metersToKilometers(double meters)
{
double kilometers = meters * 0.001;
System.out.println(meters + " meters is " +
kilometers + " kilometers.");
}


public static void metersToInches(double meters)
{
double inches = meters * 39.37;
System.out.println(meters + " meters is " +
inches + " inches.");
}

public static void metersToFeet(double meters)
{
double feet = meters * 3.281;
System.out.println(meters + " meters is " +
feet + " feet.");
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote