|
@@ -1,21 +1,72 @@
|
1
|
1
|
public class ConversionTool {
|
2
|
|
-
|
3
|
|
-
|
|
2
|
+ public static final float CM_CONVERT = 0.3937008f;
|
|
3
|
+ public static final float IN_CONVERT = 2.54f;
|
|
4
|
+ public static final float FT_CONVERT = 3.28f;
|
|
5
|
+ public static final float M_CONVERT = 0.3048f;
|
|
6
|
+ public static final float CELSIUS_CONVERT = 1.8f;
|
|
7
|
+ public static final float CELSIUS_CSTNT2 = 32.0f;
|
|
8
|
+ public static final float FAHRENHT_CONVERT = 32.0f;
|
|
9
|
+ public static final float FAHRENHT_CSTNT2 = 5.0f;
|
|
10
|
+ public static final float FAHRENHT_CSTNT3 = 9.0f;
|
|
11
|
+ public static final float MPH_CONVERT = 1.6093440f;
|
|
12
|
+ public static final float KPH_CONVERT = 0.6214f;
|
|
13
|
+
|
|
14
|
+ public static float cmToInches;
|
|
15
|
+ public static float inchesToCm;
|
|
16
|
+ public static float ftToMeters;
|
|
17
|
+ public static float metersToFt;
|
|
18
|
+ public static float mphToKph;
|
|
19
|
+ public static float kphToMph;
|
|
20
|
+
|
4
|
21
|
public static void main(String[] args){}
|
|
22
|
+
|
|
23
|
+ public static float CentimetersToInches(float centimeters){
|
|
24
|
+ cmToInches = centimeters * CM_CONVERT;
|
|
25
|
+ if(cmToInches < 0) {return 0f;}
|
|
26
|
+ else
|
|
27
|
+ return cmToInches;
|
|
28
|
+ }
|
5
|
29
|
|
6
|
|
- public static float CentimetersToInches(float centimeters){}
|
7
|
|
-
|
8
|
|
- public static float InchesToCentimeters(float inches){}
|
9
|
|
-
|
10
|
|
- public static float FeetToMeters(float feet){}
|
11
|
|
-
|
12
|
|
- public static float MetersToFeet(float meters){}
|
13
|
|
-
|
14
|
|
- public static float CelsiusToFahrenheit(float celsius){}
|
15
|
|
-
|
16
|
|
- public static float FahrenheitToCelsius(float fahrenheit){}
|
|
30
|
+ public static float InchesToCentimeters(float inches){
|
|
31
|
+ inchesToCm = inches * IN_CONVERT;
|
|
32
|
+ if(inchesToCm < 0) {return 0f;}
|
|
33
|
+ else
|
|
34
|
+ return inchesToCm;
|
|
35
|
+ }
|
17
|
36
|
|
18
|
|
- public static float MphToKph(float mph){}
|
|
37
|
+ public static float FeetToMeters(float feet){
|
|
38
|
+ ftToMeters = feet / FT_CONVERT;
|
|
39
|
+ if(ftToMeters < 0) {return 0f;}
|
|
40
|
+ else
|
|
41
|
+ return ftToMeters;
|
|
42
|
+ }
|
|
43
|
+
|
|
44
|
+ public static float MetersToFeet(float meters){
|
|
45
|
+ metersToFt = meters / M_CONVERT;
|
|
46
|
+ if(metersToFt < 0) {return 0f;}
|
|
47
|
+ else
|
|
48
|
+ return metersToFt;
|
|
49
|
+ }
|
|
50
|
+
|
|
51
|
+ public static float CelsiusToFahrenheit(float celsius){
|
|
52
|
+ return (CELSIUS_CONVERT * celsius) + CELSIUS_CSTNT2;
|
|
53
|
+ }
|
|
54
|
+
|
|
55
|
+ public static float FahrenheitToCelsius(float fahrenheit){
|
|
56
|
+ return ((fahrenheit - FAHRENHT_CONVERT) * FAHRENHT_CSTNT2) / FAHRENHT_CSTNT3;
|
|
57
|
+ }
|
19
|
58
|
|
20
|
|
- public static float KphToMph(float kph){}
|
|
59
|
+ public static float MphToKph(float mph){
|
|
60
|
+ mphToKph = mph * MPH_CONVERT;
|
|
61
|
+ if(mphToKph < 0) {return 0f;}
|
|
62
|
+ else
|
|
63
|
+ return mphToKph;
|
|
64
|
+ }
|
|
65
|
+
|
|
66
|
+ public static float KphToMph(float kph){
|
|
67
|
+ kphToMph = kph * KPH_CONVERT;
|
|
68
|
+ if(kphToMph < 0) {return 0f;}
|
|
69
|
+ else
|
|
70
|
+ return kphToMph;
|
|
71
|
+ }
|
21
|
72
|
}
|