My first get method should return whether someone is underweight, normal weight, over weight or obese according to their BMI.
The second get method, i was hoping, would return the same variable 'category' from the first get method (so whatever the answer was, underweight, normal weight etc..), without needing to input a double in the parentheses when i called it in the main method.
Just some background, I've created people objects in main and given them info (name, height, weight, BMI, category), then put all those people in an array list. Which is what I'm calling from.
I can call everything besides my category, which returns 'null'. Im assuming its because my second get method does not have any data assigned to it. But I'm at a loss as how to get it to return the variable from the get method above, or if thats not the proper way to do it and i should be considering something else.
ANY help or suggestions would be very appreciated. If something doesn't make sense or you need more code let me know.
public String getCategory(double bmi) {
if (bmi < 18.5) {
category = "UNDERWEIGHT";
} else if ((bmi > 18.5) && (bmi < 25)) {
category = "NORMAL WEIGHT";
} else if ((bmi > 25) && (bmi < 30)) {
category = "OVERWEIGHT";
} else if (bmi > 30) {
category = "OBESE";
}
return category;
}
public String getCategory() {
return category;
}
My array list with my people objects info, in main..
ArrayList<Person> allInfo = new ArrayList<Person>();
{
allInfo.add(andrewsInfo);
allInfo.add(boydsInfo);
allInfo.add(cathysInfo);
allInfo.add(donnasInfo);
}
Just to see if it worked i printed it...
System.out.println(allInfo.get(0).getCategory());
Returned 'null'