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
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.
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.
USE MATLAB Write a program in Matlab that would continuously ask the user for an input...
USE MATLAB Write a program in Matlab that would continuously ask the user for an input between 1 and 6, which would represent the result of rolling a die. The program would then generate a random integer between 1 and 6 and compare its value to the value entered by user. If the user’s die is larger, it should display, “Mahahanap mo na ang forever mo. Sana all!” If the user’s die is smaller, it should display, “Gising na friend,...
Write java program that will ask for the user for 2 input lines and print out...
Write java program that will ask for the user for 2 input lines and print out all words that occur 1 or more times on both lines (case sensitive). Write this without arrays and method. Here is a sample run: <Output> Enter two lines to process. The quick brown fox jumps over a lazy dog The fox hound outruns the lazy dog The words that occur on both lines are: The fox lazy dog
JAVA Take in a user input. if user input is "Leap Year" your program should run...
JAVA Take in a user input. if user input is "Leap Year" your program should run exercise 1 if user input is "word count" your program should run exercise 2 Both exercises should run in separate methods Exercise 1: write a java method to check whether a year(integer) entered by the user is a leap year or not. Exercise 2: Write a java method to count all words in a string.
Write a program that will ask the user to enter the amount of a purchase. The...
Write a program that will ask the user to enter the amount of a purchase. The program should then compute the state and county sales tax. Assume the state sales tax is 5 percent and the county sales tax is 2.5 percent. The program should display the amount of the purchase, the state sales tax, the county sales tax, the total sales tax, and the total of the sale (which is the sum of the amount of purchase plus the...
Task 2.5: Write a script that will ask the user for to input a file name...
Task 2.5: Write a script that will ask the user for to input a file name and then create the file and echo to the screen that the file name inputted had been created 1. Open a new file script creafile.sh using vi editor # vi creafile.sh 2. Type the following lines #!/bin/bash echo ‘enter a file name: ‘ read FILENAME touch $FILENAME echo “$FILENAME has been created” 3. Add the execute permission 4. Run the script #./creafile.sh 5. Enter...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT