|
@@ -1,21 +1,68 @@
|
1
|
1
|
public class ConversionTool {
|
|
2
|
+ public static final float IN_2_CM = 2.54f;
|
|
3
|
+ public static final float CM_2_IN = 1 / IN_2_CM;
|
|
4
|
+ public static final float FT_2_IN = 12f;
|
|
5
|
+ public static final float IN_2_FT = 1 / FT_2_IN;
|
|
6
|
+ public static final float M_2_CM = 100f;
|
|
7
|
+ public static final float CM_2_M = 1 / M_2_CM;
|
|
8
|
+ public static final float KM_2_CM = 100000f;
|
|
9
|
+ public static final float CM_2_KM = 1 / KM_2_CM;
|
|
10
|
+ public static final float MI_2_IN = 63360f;
|
|
11
|
+ public static final float IN_2_MI = 1 / MI_2_IN;
|
2
|
12
|
|
|
13
|
+ public static float CentimetersToInches(float centimeters){
|
|
14
|
+ float inches = 0;
|
|
15
|
+ if (centimeters > 0){
|
|
16
|
+ inches = centimeters * CM_2_IN;
|
|
17
|
+ }
|
|
18
|
+ return inches;
|
|
19
|
+ }
|
3
|
20
|
|
4
|
|
- public static void main(String[] args){}
|
|
21
|
+ public static float InchesToCentimeters(float inches){
|
|
22
|
+ float centimeters = 0;
|
|
23
|
+ if (inches > 0){
|
|
24
|
+ centimeters = inches * IN_2_CM;
|
|
25
|
+ }
|
|
26
|
+ return centimeters;
|
|
27
|
+ }
|
5
|
28
|
|
6
|
|
- public static float CentimetersToInches(float centimeters){}
|
|
29
|
+ public static float FeetToMeters(float feet){
|
|
30
|
+ float meters = 0;
|
|
31
|
+ if (feet > 0){
|
|
32
|
+ meters = feet * FT_2_IN * IN_2_CM * CM_2_M;
|
|
33
|
+ }
|
|
34
|
+ return meters;
|
|
35
|
+ }
|
7
|
36
|
|
8
|
|
- public static float InchesToCentimeters(float inches){}
|
|
37
|
+ public static float MetersToFeet(float meters){
|
|
38
|
+ float feet = 0;
|
|
39
|
+ if (meters > 0){
|
|
40
|
+ feet = meters * M_2_CM * CM_2_IN * IN_2_FT;
|
|
41
|
+ }
|
|
42
|
+ return feet;
|
|
43
|
+ }
|
9
|
44
|
|
10
|
|
- public static float FeetToMeters(float feet){}
|
|
45
|
+ public static float CelsiusToFahrenheit(float celsius){
|
|
46
|
+ return celsius * (9f/5f) + 32f;
|
|
47
|
+ }
|
11
|
48
|
|
12
|
|
- public static float MetersToFeet(float meters){}
|
|
49
|
+ public static float FahrenheitToCelsius(float fahrenheit){
|
|
50
|
+ return (fahrenheit - 32f) * (5f/9f);
|
|
51
|
+ }
|
13
|
52
|
|
14
|
|
- public static float CelsiusToFahrenheit(float celsius){}
|
|
53
|
+ public static float MphToKph(float mph){
|
|
54
|
+ float kph = 0;
|
|
55
|
+ if (mph > 0){
|
|
56
|
+ kph = mph * MI_2_IN * IN_2_CM * CM_2_KM;
|
|
57
|
+ }
|
|
58
|
+ return kph;
|
|
59
|
+ }
|
15
|
60
|
|
16
|
|
- public static float FahrenheitToCelsius(float fahrenheit){}
|
17
|
|
-
|
18
|
|
- public static float MphToKph(float mph){}
|
19
|
|
-
|
20
|
|
- public static float KphToMph(float kph){}
|
|
61
|
+ public static float KphToMph(float kph){
|
|
62
|
+ float mph = 0;
|
|
63
|
+ if (kph > 0){
|
|
64
|
+ mph = kph * KM_2_CM * CM_2_IN * IN_2_MI;
|
|
65
|
+ }
|
|
66
|
+ return mph;
|
|
67
|
+ }
|
21
|
68
|
}
|