BAEL-5708: Create a BMI Calculator in Java (#12695)
* Deep vs Shallow copy of an object in java * update indentaions * Create a BMI Caclualtor in Java * Create a BMI Caclualtor in Java * Delete unused packages * BAEL-5708: Create a BMI Calculator in Java * BAEL-5708: Create a BMI Calculator in Java
This commit is contained in:
parent
a8f010e50e
commit
29d9ddb3b1
|
@ -0,0 +1,18 @@
|
||||||
|
package com.baeldung.math.bmicalculator;
|
||||||
|
|
||||||
|
public class BMICalculator {
|
||||||
|
|
||||||
|
public static String calculateBMI(double weight, double height) {
|
||||||
|
|
||||||
|
double bmi = weight / (height * height);
|
||||||
|
|
||||||
|
if (bmi < 18.5)
|
||||||
|
return "Underweight";
|
||||||
|
else if (bmi < 25)
|
||||||
|
return "Normal";
|
||||||
|
else if (bmi < 30)
|
||||||
|
return "Overweight";
|
||||||
|
else
|
||||||
|
return "Obese";
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
package com.baeldung.math.bmicalculator;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
public class BMICalculatorUnitTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenBMIIsGreaterThanThirty_thenObese() {
|
||||||
|
|
||||||
|
double weight = 100;
|
||||||
|
double height = 1.524;
|
||||||
|
String actual = BMICalculator.calculateBMI(weight, height);
|
||||||
|
String expected = "Obese";
|
||||||
|
|
||||||
|
assertThat(actual).isEqualTo(expected);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue