Question: Java Lab Write a program that uses one or more if statements and a loops to solve the following problem convert an amount entered to

Java Lab

Write a program that uses one or more if statements and a loops to solve the following problem convert an amount entered to another unit of measure

The structure will look like this:

Define conversionAmount, a double, and conversionCode, a String.

Welcome the user to the Conversion Calculator

Do until a valid number is entered.

Try Prompt the user for a number (type double)

Clear input stream

Break out of loop

Catch

Non-numeric input

Inform the user of error

Clear input stream

End of first do

Do until a valid code is entered.

Display list of acceptable codes and what they mean

Prompt user for the code of conversion calculation to apply.

If code entered is one of the 4 valid codes, then

Perform the conversion

Display the formatted and labeled result (all decimals to 5 places)

Break out of loop

Else

Inform user of error

End of second do

Thank the user for using your application Here are codes and conversions: GL = Gallon to Liter IC = Inch to Centimeter PK = Pound to Kilogram MK = Mile to Kilometer

For instance, if the user inputs GL as their conversion type, the program will then take their numeric input as gallons and convert it to liters. The liters value would then be output to the user. Please find additional information below to assist you in solving this problem: 1 Gallon = 3.78541178 Liters 1 Inch = 2.5 Centimeters 1 Pound = 0.45359237 Kilograms 1 Mile = 1.609344 Kilometers Use the try-catch idea to only allow numeric input for conversion amount...if a user does not enter a valid number the program should inform the user and force the correct input. < IT SHOULD NOT CRASH>.

The loop for the conversion Code does not need a try-catch as the input is a String

Here is a sample run that displays conversions to 3 decimalsyou must display 5...

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!