Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 1 addition & 17 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions .idea/copyright/profiles_settings.xml

This file was deleted.

49 changes: 35 additions & 14 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions .idea/encodings.xml → .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion conversion.iml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
Expand Down
73 changes: 65 additions & 8 deletions src/main/java/ConversionTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}
28 changes: 23 additions & 5 deletions src/test/java/ConversionToolSpec.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

public class ConversionToolSpec {

// centimeters to inches
@Test
public void shouldConvertCentimetersToInches() {
float inches = ConversionTool.CentimetersToInches(2f);
Expand All @@ -19,6 +20,8 @@ public void shouldConvertNegativeCentimetersToZeroInches() {
assertEquals(0, inches, 0.0);
}


// inches to centimeters
@Test
public void shouldConvertInchesToCentimeters() {
float centimeters = ConversionTool.InchesToCentimeters(4f);
Expand All @@ -35,6 +38,8 @@ public void shouldConvertNegativeInchesToZeroCentimeters() {
assertEquals(0, centimeters, 0.0);
}


// feet to meters
@Test
public void shouldConvertFeetToMeters() {
float meters = ConversionTool.FeetToMeters(5f);
Expand All @@ -51,6 +56,8 @@ public void shouldConvertNegativeFeetToZeroMeters() {
assertEquals(0, meters, 0.0);
}


// meters to feet
@Test
public void shouldConvertMetersToFeet() {
float feet = ConversionTool.MetersToFeet(9f);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -110,4 +127,5 @@ public void shouldConvertNegativeKphToZeroMph(){
assertEquals(0, mph, 0.0);
}


}
Binary file modified target/classes/ConversionTool.class
Binary file not shown.
Binary file modified target/test-classes/ConversionToolSpec.class
Binary file not shown.