|
@@ -1,21 +1,83 @@
|
1
|
|
-public class ConversionTool {
|
2
|
|
-
|
3
|
|
-
|
4
|
|
- public static void main(String[] args){}
|
5
|
|
-
|
6
|
|
- public static float CentimetersToInches(float centimeters){}
|
7
|
|
-
|
8
|
|
- public static float InchesToCentimeters(float inches){}
|
9
|
1
|
|
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){}
|
|
2
|
+public class ConversionTool {
|
17
|
3
|
|
18
|
|
- public static float MphToKph(float mph){}
|
19
|
4
|
|
20
|
|
- public static float KphToMph(float kph){}
|
|
5
|
+ public static void main(String[] args) {}
|
|
6
|
+
|
|
7
|
+ public static float CentimetersToInches(float centimeters) {
|
|
8
|
+
|
|
9
|
+ float inches = centimeters * 0.393701f;
|
|
10
|
+ if (centimeters <= 0) {
|
|
11
|
+ return 0;
|
|
12
|
+ }
|
|
13
|
+ else {
|
|
14
|
+ return inches;
|
|
15
|
+ }
|
|
16
|
+ }
|
|
17
|
+
|
|
18
|
+ public static float InchesToCentimeters(float inches) {
|
|
19
|
+ float centimeters = 2.54f * inches;
|
|
20
|
+
|
|
21
|
+ if (inches <= 0) {
|
|
22
|
+ return 0;
|
|
23
|
+
|
|
24
|
+ }
|
|
25
|
+ else {
|
|
26
|
+ return centimeters;
|
|
27
|
+ }
|
|
28
|
+ }
|
|
29
|
+
|
|
30
|
+ public static float FeetToMeters(float feet) {
|
|
31
|
+ float meters = InchesToCentimeters(feet * 12) / 100f;
|
|
32
|
+
|
|
33
|
+ if (feet <= 0) {
|
|
34
|
+ return 0;
|
|
35
|
+ }
|
|
36
|
+ else {
|
|
37
|
+ return meters;
|
|
38
|
+ }
|
|
39
|
+ }
|
|
40
|
+
|
|
41
|
+ public static float MetersToFeet(float meters) {
|
|
42
|
+ float feet = CentimetersToInches(meters * 100) / 12f;
|
|
43
|
+
|
|
44
|
+ if (meters <= 0) {
|
|
45
|
+ return 0;
|
|
46
|
+ }
|
|
47
|
+ else {
|
|
48
|
+ return feet;
|
|
49
|
+ }
|
|
50
|
+ }
|
|
51
|
+
|
|
52
|
+ public static float FahrenheitToCelsius(float fahrenheit) {
|
|
53
|
+ float celsius = (fahrenheit - 32) / 1.8f;
|
|
54
|
+
|
|
55
|
+ return celsius;
|
|
56
|
+ }
|
|
57
|
+
|
|
58
|
+ public static float CelsiusToFahrenheit(float celsius) {
|
|
59
|
+ float fahrenheit = (celsius * 1.8f) + 32;
|
|
60
|
+ return fahrenheit;
|
|
61
|
+ }
|
|
62
|
+
|
|
63
|
+ public static float MphToKph(float mph) {
|
|
64
|
+
|
|
65
|
+ if (mph <= 0) {
|
|
66
|
+ return 0;
|
|
67
|
+ }
|
|
68
|
+ else {
|
|
69
|
+ return mph * 1.60934f;
|
|
70
|
+ }
|
|
71
|
+ }
|
|
72
|
+
|
|
73
|
+ public static float KphToMph(float kph) {
|
|
74
|
+
|
|
75
|
+ if (kph <= 0) {
|
|
76
|
+ return 0;
|
|
77
|
+ }
|
|
78
|
+ else {
|
|
79
|
+ return kph * 0.621371f;
|
|
80
|
+ }
|
|
81
|
+ }
|
21
|
82
|
}
|
|
83
|
+
|