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:
Mahn00rMalik 2022-09-21 09:16:09 +05:00 committed by GitHub
parent a8f010e50e
commit 29d9ddb3b1
2 changed files with 37 additions and 0 deletions

View File

@ -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";
}
}

View File

@ -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);
}
}