12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- public class ConversionTool {
- private static final float CM_PER_INCH = 2.54f;
- private static final float FT_PER_M = 3.28084f;
- private static final float KM_PER_MILE = 1.60934f;
-
- public static void main(String[] args){}
-
- public static float CentimetersToInches(float centimeters){
- if (checkNegative(centimeters)) return 0f;
- return centimeters / CM_PER_INCH;
- }
-
- public static float InchesToCentimeters(float inches){
- if (checkNegative(inches)) return 0f;
- return inches * CM_PER_INCH;
- }
-
- public static float FeetToMeters(float feet){
- if (checkNegative(feet)) return 0f;
- return feet / FT_PER_M;
- }
-
- public static float MetersToFeet(float meters){
- if (checkNegative(meters)) return 0f;
- return meters * FT_PER_M;
- }
-
- public static float CelsiusToFahrenheit(float celsius){
- if (checkNegative(celsius)) return 0f;
- return celsius * 1.8f + 32.0f;
- }
-
- public static float FahrenheitToCelsius(float fahrenheit){
- if (checkNegative(fahrenheit)) return 0f;
- return (fahrenheit - 32) / 1.8f;
- }
-
- public static float MphToKph(float mph){
- if (checkNegative(mph)) return 0f;
- return mph * KM_PER_MILE;
- }
-
- public static float KphToMph(float kph){
- if (checkNegative(kph)) return 0f;
- return kph / KM_PER_MILE;
- }
-
- private static boolean checkNegative(float value) {
- if (value < 0) {
- return true;
- }
- return false;
- }
- }
|