12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- public class ConversionTool {
- public static final float CM_CONVERT = 0.3937008f;
- public static final float IN_CONVERT = 2.54f;
- public static final float FT_CONVERT = 3.28f;
- public static final float M_CONVERT = 0.3048f;
- public static final float CELSIUS_CONVERT = 1.8f;
- public static final float CELSIUS_CSTNT2 = 32.0f;
- public static final float FAHRENHT_CONVERT = 32.0f;
- public static final float FAHRENHT_CSTNT2 = 5.0f;
- public static final float FAHRENHT_CSTNT3 = 9.0f;
- public static final float MPH_CONVERT = 1.6093440f;
- public static final float KPH_CONVERT = 0.6214f;
-
- public static float cmToInches;
- public static float inchesToCm;
- public static float ftToMeters;
- public static float metersToFt;
- public static float mphToKph;
- public static float kphToMph;
-
- public static void main(String[] args){}
-
- public static float CentimetersToInches(float centimeters){
- cmToInches = centimeters * CM_CONVERT;
- if(cmToInches < 0) {return 0f;}
- else
- return cmToInches;
- }
-
- public static float InchesToCentimeters(float inches){
- inchesToCm = inches * IN_CONVERT;
- if(inchesToCm < 0) {return 0f;}
- else
- return inchesToCm;
- }
-
- public static float FeetToMeters(float feet){
- ftToMeters = feet / FT_CONVERT;
- if(ftToMeters < 0) {return 0f;}
- else
- return ftToMeters;
- }
-
- public static float MetersToFeet(float meters){
- metersToFt = meters / M_CONVERT;
- if(metersToFt < 0) {return 0f;}
- else
- return metersToFt;
- }
-
- public static float CelsiusToFahrenheit(float celsius){
- return (CELSIUS_CONVERT * celsius) + CELSIUS_CSTNT2;
- }
-
- public static float FahrenheitToCelsius(float fahrenheit){
- return ((fahrenheit - FAHRENHT_CONVERT) * FAHRENHT_CSTNT2) / FAHRENHT_CSTNT3;
- }
-
- public static float MphToKph(float mph){
- mphToKph = mph * MPH_CONVERT;
- if(mphToKph < 0) {return 0f;}
- else
- return mphToKph;
- }
-
- public static float KphToMph(float kph){
- kphToMph = kph * KPH_CONVERT;
- if(kphToMph < 0) {return 0f;}
- else
- return kphToMph;
- }
- }
|