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.
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...
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
Write a program to find the prime numbers IN JAVA Ask user to input the integer...
Write a program to find the prime numbers IN JAVA Ask user to input the integer number test the number whether it is a prime number or not Then, print “true” or “false” depending on whether the number is prime or isn’t. Hint: number is prime when is has exactly 2 factors: one and itself. By this definition, number 1 is a special case and is NOT a prime. Use idea of user input, cumulative sum, and loop to solve...
Program 3.5 - Conversion Program   - NOW using cin statements to gather input from user Concepts...
Program 3.5 - Conversion Program   - NOW using cin statements to gather input from user Concepts Covered:  Chapter 2 – cout ,   math, data types, Chapter 3 , gathering both numeric & string input from user Programs 2-21, 2-22, 2-23, 2-28 should help with math and programs 3.5, 3.17 and 3.19 should help you with the new concepts introduced with this program. Program Purpose:  To help you understand the concept of using both proper numeric variables and string variables. To give you practice...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT