123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- public class ConversionTool {
- public static final float IN_2_CM = 2.54f;
- public static final float CM_2_IN = 1 / IN_2_CM;
- public static final float FT_2_IN = 12f;
- public static final float IN_2_FT = 1 / FT_2_IN;
- public static final float M_2_CM = 100f;
- public static final float CM_2_M = 1 / M_2_CM;
- public static final float KM_2_CM = 100000f;
- public static final float CM_2_KM = 1 / KM_2_CM;
- public static final float MI_2_IN = 63360f;
- public static final float IN_2_MI = 1 / MI_2_IN;
-
- public static float CentimetersToInches(float centimeters){
- float inches = 0;
- if (centimeters > 0){
- inches = centimeters * CM_2_IN;
- }
- return inches;
- }
-
- public static float InchesToCentimeters(float inches){
- float centimeters = 0;
- if (inches > 0){
- centimeters = inches * IN_2_CM;
- }
- return centimeters;
- }
-
- public static float FeetToMeters(float feet){
- float meters = 0;
- if (feet > 0){
- meters = feet * FT_2_IN * IN_2_CM * CM_2_M;
- }
- return meters;
- }
-
- public static float MetersToFeet(float meters){
- float feet = 0;
- if (meters > 0){
- feet = meters * M_2_CM * CM_2_IN * IN_2_FT;
- }
- return feet;
- }
-
- public static float CelsiusToFahrenheit(float celsius){
- return celsius * (9f/5f) + 32f;
- }
-
- public static float FahrenheitToCelsius(float fahrenheit){
- return (fahrenheit - 32f) * (5f/9f);
- }
-
- public static float MphToKph(float mph){
- float kph = 0;
- if (mph > 0){
- kph = mph * MI_2_IN * IN_2_CM * CM_2_KM;
- }
- return kph;
- }
-
- public static float KphToMph(float kph){
- float mph = 0;
- if (kph > 0){
- mph = kph * KM_2_CM * CM_2_IN * IN_2_MI;
- }
- return mph;
- }
- }
|