After not getting the BMR calculator to work as intended I've decided to go with something a little bit simpler and try to make a calculator for BMI (since it doesn't require different methods for genders) that would more or less be rewritten from the BMR calculator. The problem is that I'm not really confident on how I'm supposed to use the math for this because I thought that I could just round off the answer and let it return as a float but when I use the test class it tells me that the BMI of person 1 is 0. Is there any way to fix this while keeping the calc method as a float?
BMI Class
public class BMI {
private String name;
private float weight; //Meters
private float height; //Kilograms
public BMI(String n, float w, float h) //CONSTRUCTOR
{
n = name;
w = weight;
h = height;
}
public float calculateBMI() //MATH CALCULATIONS
{
return Math.round((weight * 2.20462) / (height * 39.3701)); //The numbers mulitplied by height & weight are the conversions
}
public String catagoryBMI() {
String getcata;
if (calculateBMI() <= 15) {
getcata = "Very severely underweight";
} else if (calculateBMI() < 16.0) {
getcata = "Severely underweight";
} else if (calculateBMI() < 18.0) {
getcata = "Underweight";
} else if (calculateBMI() < 25) {
getcata = "Normal (healthy weight)";
} else if (calculateBMI() < 30) {
getcata = "Overweight";
} else if (calculateBMI() < 35) {
getcata = "Obese Class I (Moderately obese)";
} else if (calculateBMI() < 40) {
getcata = "Obese Class II (Severely obese)";
} else {
getcata = "Obese Class III (Very severely obese)";
}
return getcata;
}
}
BMI Test Class
public class BMITest {
public static void main(String[] args) {
BMI bmi1 = new BMI("BMI TEST1", 65.7709f, 1.79832f);
//p1BMI = bmi1.calculateBMI();
//p1CATA = bmi1.catagoryBMI();
System.out.println("BMI PERSON 1: " + bmi1.calculateBMI());
System.out.println("CATAGORY PERSON 1: " + bmi1.catagoryBMI());
}
}