|
@@ -1,21 +1,54 @@
|
1
|
1
|
public class ConversionTool {
|
2
|
|
-
|
|
2
|
+ private static final float CM_PER_INCH = 2.54f;
|
|
3
|
+ private static final float FT_PER_M = 3.28084f;
|
|
4
|
+ private static final float KM_PER_MILE = 1.60934f;
|
3
|
5
|
|
4
|
6
|
public static void main(String[] args){}
|
5
|
7
|
|
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){}
|
17
|
|
-
|
18
|
|
- public static float MphToKph(float mph){}
|
19
|
|
-
|
20
|
|
- public static float KphToMph(float kph){}
|
|
8
|
+ public static float CentimetersToInches(float centimeters){
|
|
9
|
+ if (checkNegative(centimeters)) return 0f;
|
|
10
|
+ return centimeters / CM_PER_INCH;
|
|
11
|
+ }
|
|
12
|
+
|
|
13
|
+ public static float InchesToCentimeters(float inches){
|
|
14
|
+ if (checkNegative(inches)) return 0f;
|
|
15
|
+ return inches * CM_PER_INCH;
|
|
16
|
+ }
|
|
17
|
+
|
|
18
|
+ public static float FeetToMeters(float feet){
|
|
19
|
+ if (checkNegative(feet)) return 0f;
|
|
20
|
+ return feet / FT_PER_M;
|
|
21
|
+ }
|
|
22
|
+
|
|
23
|
+ public static float MetersToFeet(float meters){
|
|
24
|
+ if (checkNegative(meters)) return 0f;
|
|
25
|
+ return meters * FT_PER_M;
|
|
26
|
+ }
|
|
27
|
+
|
|
28
|
+ public static float CelsiusToFahrenheit(float celsius){
|
|
29
|
+ if (checkNegative(celsius)) return 0f;
|
|
30
|
+ return celsius * 1.8f + 32.0f;
|
|
31
|
+ }
|
|
32
|
+
|
|
33
|
+ public static float FahrenheitToCelsius(float fahrenheit){
|
|
34
|
+ if (checkNegative(fahrenheit)) return 0f;
|
|
35
|
+ return (fahrenheit - 32) / 1.8f;
|
|
36
|
+ }
|
|
37
|
+
|
|
38
|
+ public static float MphToKph(float mph){
|
|
39
|
+ if (checkNegative(mph)) return 0f;
|
|
40
|
+ return mph * KM_PER_MILE;
|
|
41
|
+ }
|
|
42
|
+
|
|
43
|
+ public static float KphToMph(float kph){
|
|
44
|
+ if (checkNegative(kph)) return 0f;
|
|
45
|
+ return kph / KM_PER_MILE;
|
|
46
|
+ }
|
|
47
|
+
|
|
48
|
+ private static boolean checkNegative(float value) {
|
|
49
|
+ if (value < 0) {
|
|
50
|
+ return true;
|
|
51
|
+ }
|
|
52
|
+ return false;
|
|
53
|
+ }
|
21
|
54
|
}
|