# EECS 1030 Z, Summer 2015

## UnitConverter

Use the following code to create a class named "UnitConverter":

```/**	This utility class facilitates conversion from metric units to
*	imperial units.
*/
public class UnitConverter
{
/** Represents the number of centimetres in an inch. */
public static final double CM_PER_INCH = 2.54;

// Include additional constants here as needed.
// Use the one above as a guide.
;

// This line prevents clients from instantiating the class.
private UnitConverter() {}

/**	Converts the passed value in centimetres to the corresponding
*	length in inches.
*
*	@param cm A length in centimetres.
*	@return The passed length in inches.
*/
public static double cmToInches(double cm)
{
double result = cm / CM_PER_INCH;
return result;
}

/**	Write a description here.
*	Use the method above as a guide.
*/
public static double kgToPounds(double kg)
{
;
return 0;
}

/**	Write a description here.
*	Use the method above as a guide.
*/
public static double cToFahrenheit(double c)
{
;
return 0;
}
}
```
The method to convert from centimetres to inches is already completed. Using this as an example, complete the methods to convert kilograms and degrees Celsius. Use Google's unit conversion functionality to help develop and test your calculations. Create constants as needed.

Use the following code to create a class named "UnitConverterUI":

```import java.io.PrintStream;
import java.util.Scanner;

/**	This class serves as the user interface for the UnitConverter
*	class.
*/
public class UnitConverterUI
{
public static void main(String[] args)
{
PrintStream out = System.out;
Scanner in = new Scanner(System.in);

out.println("Conversion codes:");
out.println(" 1: cm -> inches");
out.println(" 2: kg -> pounds");
out.println(" 3: \u00B0C -> \u00B0F");
out.print("Enter the value to convert: ");
double value = in.nextDouble();
out.print("Enter the conversion code:  ");
int code = in.nextInt();

double result;
// Your code to convert the values goes here.
;

out.printf("The converted value is %.3f.\n", result);
}
}
```
Complete the code so that the user's input is converted using the static methods in the UnitConverter utility class.

In the UnitConverter class, write documentation for each constant and method. Use the existing comments as examples. Comments that start with /** are Javadoc comments and will appear in the class's API. To create the API documentation using the terminal, navigate to the directory containing UnitConverter.java. Enter the command javadoc UnitConverter.java. Using Eclipse, open the Project menu and select "Generate Javadoc". Expand your 1030 project folder and select the UnitConverter class, and click "Finish". In an internet browser, navigate to the directory that contains the generated UnitConverter.html file and open it.

### Sample Runs

Run:

```	Conversion codes:
1: cm -> inches
2: kg -> pounds
3: °C -> °F
Enter the value to convert: 10
Enter the conversion code:  2
The converted value is 22.000.
```

--- End of Exercise ---