I'm doing a project assignment for school. The assignment is to create a conversion program that 1) prompts the user to enter a value in meters 2) then asks which they want to convert meters to: km, inches, or feet. After the conversion it should repeat the menu until they choose #4 to quit. We have just learned about different methods, so I'm getting stuck on passing the meters value to the other methods. Any assistance is appreciated.
import java.util.*; public class ConversionJMB { public static void main (String[] args) { Scanner keyboard = new Scanner(System.in); System.out.print("Enter a distance in meters: " ); double meters = keyboard.nextDouble(); while (meters <= 0) { System.out.print("The value must be greater than zero." ); System.out.print("Enter a distance in meters: " ); meters = keyboard.nextInt(); } menu(); } public static void menu() { Scanner keyboard = new Scanner(System.in); 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"); int choice = keyboard.nextInt(); switch (choice) { case 1: showKilometers(); break; case 2: showInches(); break; case 3: showFeet(); break; case 4: System.out.println("Bye"); System.exit(0); break; default: System.out.println("Choice " + choice + " is not a valid menu option."); } } public static void showKilometers(double meters) { double kilometers = meters * 0.001; System.out.println(meters + " meters is " + kilometers + " kilometers."); } public static void showInches(double meters) { double inches = meters * 39.37; System.out.println(meters + " meters is " + inches + " inches."); } public static void showFeet(double meters) { double feet = meters * 3.281; System.out.println(meters + " meters is " + feet + " feet."); } }