From 31ba84bacd945aa5d8c0aff97caf5b5eb9013ab5 Mon Sep 17 00:00:00 2001 From: Matt Wu Date: Fri, 12 May 2017 11:23:31 -0400 Subject: [PATCH] finished all conversion --- .idea/.name | 1 + .idea/compiler.xml | 18 +---- .idea/copyright/profiles_settings.xml | 3 - .idea/misc.xml | 49 +++++++++---- .idea/{encodings.xml => vcs.xml} | 4 +- conversion.iml | 1 - src/main/java/ConversionTool.java | 73 +++++++++++++++++-- src/test/java/ConversionToolSpec.java | 28 +++++-- target/classes/ConversionTool.class | Bin 1471 -> 1278 bytes target/test-classes/ConversionToolSpec.class | Bin 3584 -> 3584 bytes 10 files changed, 127 insertions(+), 50 deletions(-) create mode 100644 .idea/.name delete mode 100644 .idea/copyright/profiles_settings.xml rename .idea/{encodings.xml => vcs.xml} (51%) 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 7d20ebc7517733b6c814cac4fcef422936d99bfb..8e1775fdb6de23b38f739dc8d7855a5c6f87a6ae 100644 GIT binary patch literal 1278 zcmaKq&rcIU6vyA-vaQ<{DlOp8iuDIADg_jb!O(_k6GHJ98!n!<>$Dx(?vU-4tMOnw znR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