Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing Fundamentals Design And Implementation

Authors: KROENKE DAVID M.

1st Edition

8120322258, 978-8120322257

More Books

Students also viewed these Databases questions

Question

=+Does it keep the visitor reading?

Answered: 1 week ago

Question

7. Do the organizations social activities reflect diversity?

Answered: 1 week ago

Question

What qualities do you see as necessary for your line of work?

Answered: 1 week ago