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

Write a program in Java that asks the user to enter a distance in meters. The pr

ID: 3620506 • Letter: W

Question

Write a program in Java that asks the user to enter a distance in meters. The program will then present the following menu selections: 1. Convert to kilometers 2.Convert to inches 3.Convert to feet 4.Quit the program write a void method named showKilometers , showInches,showFeet
kilometers = meters*0.001 inches=meters*39.37 feet=meters*3.281 write a void menu method that displays the selections above The program should not accept negative numbers for meters if the user selects invalid number from the menu, an error is displayed The program should continue to display the menu until the user enters 4 to Quit the program
Write a program in Java that asks the user to enter a distance in meters. The program will then present the following menu selections: 1. Convert to kilometers 2.Convert to inches 3.Convert to feet 4.Quit the program write a void method named showKilometers , showInches,showFeet
kilometers = meters*0.001 inches=meters*39.37 feet=meters*3.281 write a void menu method that displays the selections above The program should not accept negative numbers for meters if the user selects invalid number from the menu, an error is displayed The program should continue to display the menu until the user enters 4 to Quit the program

Explanation / Answer

please rate - thanks import java.util.Scanner;

public class Main
{
public static void main(String[] args)
    { Scanner in = new Scanner(System.in);
      int choice;
       double meters;
          System.out.print("enter a distance in meters: ");
        meters=in.nextDouble();
          while(meters<0)
              {System.out.println("must be>=0");
               System.out.print("enter a distance in meters: ");
             meters=in.nextDouble();
               }
          menu();
          choice=in.nextInt();
          while(choice!=4)
          {if(choice==1)
              showKilometers(meters);
           else if(choice==2)
                showInches(meters);
           else if(choice==3)
                showFeet(meters);  
           else
                System.out.println("must be between 1 and 4");
           menu();
          choice=in.nextInt();

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

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

}
public static void showFeet(double meters)
{ System.out.println(meters+"meters= "+meters*3.281+" 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