I want to be able to retrieve the value of the body mass index and use it to render a comment as per the range obtained after the calculation.
The code I have below does not achieve it. I tried to put a switch statement in there, but it claims, modelmap is null, I got that. But, I still need to get this task done. I believe I should be using something different from modelmap.
@RequestMapping(value = "/")
        public String index(@RequestParam(required = false) Integer weight,
                @RequestParam(required = false) Double height,
                @RequestParam(required = false) String unitweight,
                @RequestParam(required = false) String unitheight,
                @RequestParam(required = false) String gender,
                @RequestParam(required = false) String comment,
                ModelMap modelMap) {
            if(weight!=null&&height!=null) {
                ImcCalculadora bmIcalc = new ImcCalculadora();
                modelMap.put("bmi", "O Seu Indice de massa corporal é: " + bmIcalc.getBmiKgCm(weight, height, unitweight, unitheight, comment));
                
                                
                modelMap.put("weight", weight);
                modelMap.put("height", height);
                modelMap.put("unitweight", unitweight);
                modelMap.put("unitheight", unitheight);
                modelMap.put("comment", comment);
                modelMap.put("gender", gender );
                modelMap.put("genderimg", gender+".png");
    
    
            }
            return "index";
        }
Below is my model code:
public double getBmiKgCm(int weight, double height, String unitweight,String unitheight, String comment) {   
                        
            if (height == 0 || weight == 0) {
                System.out.println("Valor Incorrecto");
            }
            double factor1 = unitheight.equals("cm") ? 1 : 2.54 ;
            double factor2 = unitweight.equals("kg") ? 1 : 2.20462262 ;
            double bmi = (weight/factor2) / (height * height);
            double roundOff = Math.round(bmi * 100.0) / 100.0;   
            
            if (roundOff < 18.5) {
                System.out.println("less than 18.5");
                comment = "Underweight";
            } else if ((roundOff >= 18.5 || (bmi) <= 24.9)) {
                System.out.println("between 18.5 and 24.9");
                comment = "Normal";
            } else if (roundOff >= 25 || bmi <= 29.9) {
                System.out.println("between 25 and 29.9");
                comment = "Overweight";
            } else {
                System.out.println("greater than 30");
                comment = "Obese";
            }              
            return roundOff;
        }
 
    