• Sign in to Neowin Faster!

    Create an account on Neowin to contribute and support the site.

  • 0
Sign in to follow this  

Need some help

Question

chromedude    0

still a bit new to java, and this is causing me a little headaches:

 

Write a program that uses one or more if statements and a loop to solve the following problem:

Prompt the user for a number (type double) and the type of conversion calculation to apply.  You will continue to prompt for conversions until the user enters a code of "XX". Once the user supplies the value and the type of conversion, your program should apply the appropriate conversion and display the result.  For the conversion type, the user will enter one of the following conversion codes:  GL, IC, PK, MK.

Based on the user's input, your program will compute and display the appropriate result.  See below for the meaning of the codes:

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 liter’s 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

When comparing the user's input for conversion type to a string like "GL", make sure that you use the following syntax:  

    type.equals("GL")

where type is the name of the variable that you have used to hold the conversion type.  The reasoning behind this is described on page 678 "String Method equals" and "Comparing Strings with the == Operator" of your textbook.   Limit your output to 5 decimal places. 

Use the try-catch idea to only allow numeric input...if a user does not enter a valid number the program should inform the user and exit.

< IT SHOULD NOT CRASH>  Likewise, if a user does not enter a valid Conversion Type the program should inform the user and then exit. 

 

When the user has entered a number and a good conversion code your output should look like this: 

Welcome to the Conversion Calculator! 

Please input an amount:  3.75
Please Input a Conversion Type:  GL
3.75 Gallons = 14.19629 Liters 

Thank you for using the Conversion Calculator  

Share this post


Link to post
Share on other sites

1 answer to this question

Recommended Posts

  • 0
Jim K    12,621

Welcome to the Neowin.

 

Please have a read of this pinned topic.

https://www.neowin.net/forum/topic/1175473-asking-for-help-with-your-assignments/

 

Members may provide pointers with your work if something isn't working.  However, Neowin will not complete your homework for you. 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.