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