0

So I've been getting the error The method interpretBMI(double) is undefined for the type Main and The method calculateBMI(double, double) is undefined for the type Main.

Below is where I'm calling the functions. The functions are defined in a separate class in Eclipse(Jdk 17.0.1).

        for(int i=0;i<Size;i++) {
            String name = nameArray[i];
            int age = ageArray[i];
            double weight = weightArray[i]; 
            double height = heightArray[i];
            double BMI2 = calculateBMI(weight,height);
            interpretArray[i] = "** The BMI result for " +name+ " ( Age: "+age+ " Weight: "+weight+ " Height: "+height+") is\n"+interpretBMI(BMI2);
            System.out.println(interpretArray[i]);

            }

This is the class they're defined in. They are in package part2, I tried using the default package but I got the same errors. My main method is static, all my functions are static but I get the error anyway, I could find no answer online. Thanks in advance.

package part2;

public class BmiFunctions {

    public static double calculateBMI(double weight, double height) {
        double kg= weight*(0.45359237); // converting pounds to kilograms
        double mt = height*(0.0254); // converting inches to meters
        double BMI = kg/(mt*mt); // calculating BMI
        return BMI;
    }
    
    public static String interpretBMI(double bmi) {
        
        if(bmi < 18.5)
            return "Underweight";
        else if(18.5 <= bmi && bmi <= 25.0) 
            return "Normal";
        else if(25.0 <= bmi && bmi <= 30.0) 
            return "Overweight";
        else if(30.0 <= bmi)            
            return "Obese";
        else
            return "Error";
    }
}
Milad Dastan Zand
  • 1,062
  • 1
  • 10
  • 21
Rypenguin
  • 1
  • 2
  • The method being in another class, try calling `BmiFunctions.interpretBMI(BMI2)` . – Arnaud Nov 10 '21 at 07:44
  • 1
    It worked, thank you so much! I thought java could understand it was referring to the function that i imported and totally forgot to add the class name there. – Rypenguin Nov 10 '21 at 07:46
  • Well you may also import the static methods, there is a discussion about it there : https://stackoverflow.com/questions/420791/what-is-a-good-use-case-for-static-import-of-methods – Arnaud Nov 10 '21 at 07:49

0 Answers0