In: Computer Science
Create java Class with name Conversion.
Instructions for Conversion class:
The Conversion class will contain methods designed to perform simple conversions. Specifically, you will be writing methods to convert temperature between Fahrenheit and Celsius and length between meters and inches and practicing overloading methods.
See the API document for the Conversion class for a list of the methods you will write.
Also, because all of the methods of the Conversion class will be static, you should ensure that it is not possible to create any instances of the class. You can do this by declaring a default constructor method using the private access modifier.
API Document
Methods:
Identifier: |
celsiusToFahrenheit(int temp) |
Parameters: |
temp – An int type specifying the temperature in degrees Celsius |
Return Value: |
int – The value of the parameter converted to Fahrenheit. |
Other: |
This method should be static |
Identifier: |
fahrenheitToCelsius(int temp) |
Parameters: |
temp – An int type specifying the temperature in degrees Fahrenheit. |
Return Value: |
int – The value of the parameter converted to Celsius. |
Other: |
This method should be static |
Identifier: |
metersToInches(int meters) |
Parameters: |
meters – An int type specifying the number of meters. |
Return Value: |
int – the number of inches in the parameter. |
Other: |
This method should be static |
Identifier: |
inchesToMeters(int inches) |
Parameters: |
inches – An int type specifying the number of inches. |
Return Value: |
int – the number of meters in the parameter. |
Other: |
This method should be static |
Identifier: |
celsiusToFahrenheit(double temp) |
Parameters: |
temp – A double type specifying the temperature in degrees Celsius |
Return Value: |
double – The value of the parameter converted to Fahrenheit. |
Other: |
This method should be static |
Identifier: |
fahrenheitToCelsius(double temp) |
Parameters: |
temp – A double type specifying the temperature in degrees Fahrenheit. |
Return Value: |
double – The value of the parameter converted to Celsius. |
Other: |
This method should be static |
Identifier: |
metersToInches(double meters) |
Parameters: |
meters – A double type specifying the number of meters. |
Return Value: |
double – the number of inches in the parameter. |
Other: |
This method should be static |
Identifier: |
inchesToMeters(double inches) |
Parameters: |
inches – A double specifying the number of inches. |
Return Value: |
double – the number of meters in the parameter. |
Other: |
This method should be static |
public class Conversion {
private Conversion(){
}
public static int celsiusToFahrenheit(int temp){
return 9*temp/5 + 32;
}
public static int fahrenheitToCelsius(int temp){
return ((temp - 32)*5)/9;
}
public static int metersToInches(int meters){
return (int)
(meters*39.3701);
}
public static int inchesToMeters(int inches){
return (int) (inches *
0.0254);
}
public static double celsiusToFahrenheit(double
temp){
return 9*temp/5 + 32;
}
public static double fahrenheitToCelsius(double
temp){
return ((temp - 32)*5)/9;
}
public static double metersToInches(double
meters){
return meters*39.3701;
}
public static double inchesToMeters(double
inches){
return inches * 0.0254;
}
}