Question

In: Computer Science

Question: Conversion Program * This program will ask the user to input meters * After input,...

Question: Conversion Program

* This program will ask the user to input meters

* After input, a menu will be displayed:

* 1. Convert to kilometers

* 2. Convert to inches

* 3. Convert to feet

* 4. Quit

* * The user will select the conversion and the converted answer will be displayed.

* The program should redisplay the menu for another selection.

* Quit program when user selects 4.

Hi, my instructor requirement fix the bug in the code and run the code. I try to do some code but still not running thats are below. Please someone is expert review and fix my problem..

public class MetersConversion {

public static void main(String[] args) {

// Initialize variables

int selection;

double meters;

double kilo;

double inch;

double feet;

// Input the distance in Meters to be Converted

Scanner input = new Scanner(System.in);

System.out.print("Enter distance in meters: " + meters);

selection = input.nextInt();

meters = input.nextDouble();

while (selection); {

System.out.print("1. Convert to kilometers");

System.out.print("2. Convert to inches");

System.out.print("3. Convert to feet");

System.out.print("4. Quit the program\n\n");

if(selection == 1){

kilo = meters * 0.001;

}

else if(selection == 2){

inch = meters * 36.37;

}

else if(selection == 3){

feet = meters * 3.201;

}

else if(selConv == 4){

System.out.println("Bye!");

}

}

}

}

Solutions

Expert Solution

Your given code is modified and it is working now...

import java.util.*;
public class MetersConversion {

public static void main(String[] args)
{

   // Initialize variables

   int selection;

   double meters=0;

   double kilo;
  
   double inch;
  
   double feet;
  
   // Input the distance in Meters to be Converted
  
   Scanner input = new Scanner(System.in);

  
   while (true)
   {
       System.out.println("\n*** MENU ***\n");
       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\n\n");
      
       System.out.println("Enter your choice(1-4)");
      
       selection = input.nextInt();
      
       if(selection==4)
       {
           System.out.println("Bye!");
       break;
       }
      
       System.out.println("Enter distance in meters: ");
      
       meters = input.nextDouble();
  
       if(selection == 1)
       {
  
   kilo = meters * 0.001;
   System.out.println("\n"+meters+" meters is eqquivalent to "+kilo+" kilometers");
  
       }
  
       else if(selection == 2)
       {
  
       inch = meters * 36.37;
       System.out.println("\n"+meters+" meters is eqquivalent to "+inch+" inches");
  
       }
  
       else if(selection == 3)
       {
  
       feet = meters * 3.201;
       System.out.println("\n"+meters+" meters is eqquivalent to "+feet+" feets");
  
       }
  
  
  
   }

}

}

OUTPUT:

--------------------Configuration: <Default>--------------------

*** MENU ***

1. Convert to kilometers
2. Convert to inches
3. Convert to feet
4. Quit the program


Enter your choice(1-4)
1
Enter distance in meters:
3000

3000.0 meters is eqquivalent to 3.0 kilometers

*** MENU ***

1. Convert to kilometers
2. Convert to inches
3. Convert to feet
4. Quit the program


Enter your choice(1-4)
2
Enter distance in meters:
300

300.0 meters is eqquivalent to 10911.0 inches

*** MENU ***

1. Convert to kilometers
2. Convert to inches
3. Convert to feet
4. Quit the program


Enter your choice(1-4)
3
Enter distance in meters:
300

300.0 meters is eqquivalent to 960.3000000000001 feets

*** MENU ***

1. Convert to kilometers
2. Convert to inches
3. Convert to feet
4. Quit the program


Enter your choice(1-4)
4
Bye!

Process completed.

N.B: If you face any further problem please contact through comment


Related Solutions

Write a program that will ask for the user to input a filename of a text...
Write a program that will ask for the user to input a filename of a text file that contains an unknown number of integers. And also an output filename to display results. You will read all of the integers from the input file, and store them in an array. (You may need to read all the values in the file once just to get the total count) Using this array you will find the max number, min number, average value,...
Create a small program that contains the following. ask the user to input their name ask...
Create a small program that contains the following. ask the user to input their name ask the user to input three numbers check if their first number is between their second and third numbers
Q1 Create a program that asks the user to input their budget. Then, it will ask...
Q1 Create a program that asks the user to input their budget. Then, it will ask the user to input each of their purchase until their entire budget is used up. What kind of loop do you think is the most appropriate? You don't have to create the entire program. Part of it has already been created for you (see code below). Note: Assume that the user always uses up their budget to the last cent and they don't over...
Write a Python program that will ask the user to input a word, will return the...
Write a Python program that will ask the user to input a word, will return the first letter of the input word, and ask the user to put another word, and so on, in the form of a loop. If the user chooses to stop, he or she should input the integer "0" for the loop to stop.
Write a program in C, that uses standard input and output to ask the user to...
Write a program in C, that uses standard input and output to ask the user to enter a sentence of up to 50 characters, the ask the user for a number between 1 & 10. Count the number of characters in the sentence and multiple the number of characters by the input number and print out the answer. Code so far: char sentence[50]; int count = 0; int c; printf("\nEnter a sentence: "); fgets(sentence, 50, stdin); sscanf(sentence, %s;    for(c=0;...
Ask the user to input a series of numbers, write a C# program to output the...
Ask the user to input a series of numbers, write a C# program to output the sum, max, and min. Be sure to do error checking if the user input is not a number.
Design a program that will ask the user to input two integer numbers and then perform...
Design a program that will ask the user to input two integer numbers and then perform the basic arithmetic operations such as addition and subtraction. Each calculation is done by a separate function. The main function gets the input from the user, then calls the addition function and the subtraction function one at a time to perform the calculations. Each calculation function (addition or subtraction function) performs an arithmetic operation and then returns the calculation results back to where it...
write a MIPS program to ask user to input the number of elements of array
write a MIPS program to ask user to input the number of elements of array
2. Write a program to do the following: • ask the user to input the size...
2. Write a program to do the following: • ask the user to input the size of an array of integers and allocate space for the array • ask the user to input the integer values for the array and store these values into the array • calculate and display the sum and the average of elements of the array
Python Program Write a program that will ask a user on how many input colored balls...
Python Program Write a program that will ask a user on how many input colored balls of the following codes: R-red, B-blue, W-white, G-green and O-orange -will he or she would like to enter in the program and print the total number of Red balls were encountered. Assume an uppercase and lower case letter will be accepted.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT