Question: Conversion.java Write a program that asks the user to enter a distance in meters and converts the distance to one of three different conversion options:

Conversion.java

Write a program that asks the user to enter a distance in meters and converts the distance to one of three different conversion options:

Convert to yards: 1 meter = 1.09361 yards

Convert to inches: 1 meter = 39.3701 inches

Convert to feet: 1 meter = 3.28084 feet

The code should generate a menu format for displaying instructions for the program and the menu conversion options. It should then ask the user to enter the distance and perform the necessary conversion based on the selection that was made. It should also give the user a chance to rerun the program if needed, or to quit.

You will need:

1.) Method definitions to perform the following tasks:

A.) Display the instruction and menu options should be in a void method

-Tip: You can create one void method just for greetings and instructions about the program and another method with the menu options

B.) Convert to yards should be value returning

C.) Convert to inches should be value returning

D.) Convert to feet should be value returning

-Note: the methods for B, C and D should be done separately

In the main method, you will need:

1.) A Scanner object and variables to store the distance entered, the menu selections and the users response to continue the program

2.) A dowhile loop to repeat the interactive parts of the program. The loop should contain the following:

A.) A method call to the instructions and menu choices

B.) Input validation for the menu choice (only 1, 2 or 3 should be entered)

C.) Input validation for the distance (only positive values should be entered)

D.) A switch statement to manage the selections. Each case should then redirect to one of the conversion methods. So:

- Case 1 should include a method call to converting to yards

- Case 2 should include a method call to converting to inches

- Case 3 should include a method call to converting to feet

- Note: you will not need a default if you have done the input validation in part B.

E.) The loop control variable, which allows the user to continue by typing yes, or quit by typing no.

-Tip: Use the next method to read the users response instead of nextLine

-Tip: Use the equalsIgnoreCase method to make your code more robust to responses!

3.) Comments as needed.

A sample of the (somewhat long) output (that tests all the options) is shown below:

Output Sample

Hello!

This program will convert a distance in meters to yards, inches or feet!

Select an option from the menu below to get started!

1. Convert to yards

2. Convert to inches

3. Convert to feet

Enter your choice: 4

That is an invalid selection. Re-enter your choice: 1

Enter a distance in meters: -89

Distances should be greater than 0. Re-enter your distance: 89

89.0 meters is 97.33129 yards.

Would you like to run the program again?

Type yes or no: yes

Hello!

This program will convert a distance in meters to yards, inches or feet!

Select an option from the menu below to get started!

1. Convert to yards

2. Convert to inches

3. Convert to feet

Enter your choice: 2

Enter a distance in meters: 45

45.0 meters is 1771.6499999999999 inches.

Would you like to run the program again?

Type yes or no: yes

Hello!

This program will convert a distance in meters to yards, inches or feet!

Select an option from the menu below to get started!

1. Convert to yards

2. Convert to inches

3. Convert to feet

Enter your choice: 3

Enter a distance in meters: 65

65.0 meters is 213.26500000000001 feet.

Would you like to run the program again?

Type yes or no: no

Ok, bye!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!