diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..5966089 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +conversion \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml index 3c5f7fa..7ec525c 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -1,27 +1,11 @@ - - - - - - - - - - - - - - - - + - diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml deleted file mode 100644 index e7bedf3..0000000 --- a/.idea/copyright/profiles_settings.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index dfca8c4..9338466 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,8 +1,5 @@ - - - - - - - - - - - - - - + + + + + + + + + + + 1.8 + + + + + 1.8 @@ -37,6 +47,17 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/vcs.xml similarity index 51% rename from .idea/encodings.xml rename to .idea/vcs.xml index 97626ba..35eb1dd 100644 --- a/.idea/encodings.xml +++ b/.idea/vcs.xml @@ -1,6 +1,6 @@ - - + + \ No newline at end of file diff --git a/conversion.iml b/conversion.iml index 4b044f1..d4f21b5 100644 --- a/conversion.iml +++ b/conversion.iml @@ -5,7 +5,6 @@ - diff --git a/src/main/java/ConversionTool.java b/src/main/java/ConversionTool.java index df73653..430a983 100644 --- a/src/main/java/ConversionTool.java +++ b/src/main/java/ConversionTool.java @@ -3,19 +3,76 @@ public class ConversionTool { public static void main(String[] args){} - public static float CentimetersToInches(float centimeters){} - public static float InchesToCentimeters(float inches){} + // cm to inch - public static float FeetToMeters(float feet){} + public static float CentimetersToInches(float centimeters){ - public static float MetersToFeet(float meters){} + if (centimeters <= 0){ return 0; } - public static float CelsiusToFahrenheit(float celsius){} + return (float)(centimeters * 0.393701); + } - public static float FahrenheitToCelsius(float fahrenheit){} - public static float MphToKph(float mph){} - public static float KphToMph(float kph){} + // inch to cm + public static float InchesToCentimeters(float inches){ + + if (inches <= 0){ return 0; } + + return (float)(inches * 2.54); + } + + + // feet to meters + public static float FeetToMeters(float feet){ + + if (feet <= 0){ return 0; } + + return (float)(feet * 0.3048); + } + + + // meter to feet + public static float MetersToFeet(float meters){ + + if (meters <= 0){ return 0; } + + return (float)(meters * 3.28084); + } + + + // cel to fah + public static float CelsiusToFahrenheit(float celsius){ + + return (float)(celsius * 1.8 + 32); + + } + + + // fah to cel + public static float FahrenheitToCelsius(float fahrenheit){ + + + return (float)((fahrenheit - 32) / 1.8); + } + + + // mph to kph + public static float MphToKph(float mph){ + + if (mph <= 0){ return 0; } + + return (float)(mph * 1.60934); + } + + + // kph to mph + public static float KphToMph(float kph){ + + if (kph <= 0){ return 0; } + + return (float)(kph * 0.621371); + } + } diff --git a/src/test/java/ConversionToolSpec.java b/src/test/java/ConversionToolSpec.java index 5bbfb07..5baf23c 100644 --- a/src/test/java/ConversionToolSpec.java +++ b/src/test/java/ConversionToolSpec.java @@ -3,6 +3,7 @@ public class ConversionToolSpec { + // centimeters to inches @Test public void shouldConvertCentimetersToInches() { float inches = ConversionTool.CentimetersToInches(2f); @@ -19,6 +20,8 @@ public void shouldConvertNegativeCentimetersToZeroInches() { assertEquals(0, inches, 0.0); } + + // inches to centimeters @Test public void shouldConvertInchesToCentimeters() { float centimeters = ConversionTool.InchesToCentimeters(4f); @@ -35,6 +38,8 @@ public void shouldConvertNegativeInchesToZeroCentimeters() { assertEquals(0, centimeters, 0.0); } + + // feet to meters @Test public void shouldConvertFeetToMeters() { float meters = ConversionTool.FeetToMeters(5f); @@ -51,6 +56,8 @@ public void shouldConvertNegativeFeetToZeroMeters() { assertEquals(0, meters, 0.0); } + + // meters to feet @Test public void shouldConvertMetersToFeet() { float feet = ConversionTool.MetersToFeet(9f); @@ -67,17 +74,25 @@ public void shouldConvertNegativeMetersToZeroFeet() { assertEquals(0, feet, 0.0); } - @Test - public void shouldConvertFahrenheitToCelsius() { - float celsius = ConversionTool.FahrenheitToCelsius(80); - assertEquals(26.67, celsius, 0.01); - } + + + // celsius to fahrenheit @Test public void shouldConvertCelsiusToFahrenheit() { float fahrenheit = ConversionTool.CelsiusToFahrenheit(26.67f); assertEquals(80, fahrenheit, 0.01); } + + // fahrenheit to celsius + @Test + public void shouldConvertFahrenheitToCelsius() { + float celsius = ConversionTool.FahrenheitToCelsius(80); + assertEquals(26.67, celsius, 0.01); + } + + + // mph to kp @Test public void shouldConvertMphToKph(){ float kph = ConversionTool.MphToKph(24f); @@ -94,6 +109,8 @@ public void shouldConvertNegativeMphToZeroKph(){ assertEquals(0, kph, 0.0); } + + // kph to mph @Test public void shouldConvertKphToMph(){ float mph = ConversionTool.KphToMph(6.44f); @@ -110,4 +127,5 @@ public void shouldConvertNegativeKphToZeroMph(){ assertEquals(0, mph, 0.0); } + } diff --git a/target/classes/ConversionTool.class b/target/classes/ConversionTool.class index 7d20ebc..8e1775f 100644 Binary files a/target/classes/ConversionTool.class and b/target/classes/ConversionTool.class differ diff --git a/target/test-classes/ConversionToolSpec.class b/target/test-classes/ConversionToolSpec.class index 2cc6d49..ea6c988 100644 Binary files a/target/test-classes/ConversionToolSpec.class and b/target/test-classes/ConversionToolSpec.class differ