Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am have issues with this code. public class BMI { public static doulbe getBMI(

ID: 3912611 • Letter: I

Question

I am have issues with this code.

public class BMI {
public static doulbe getBMI(double weight, double height){
BMI bmi1 = new BMI("Doug Yang", 52, 245, 66);
System.out.println("The BMI for " + bmi1.getName() + " is "
+ bmi1.getBMI() + " " + bmi1.getStatus());
  
BMI bmi2 = new BMI("Kaye Wi", 34, 176, 61);
System.out.println("The BMI for " + bmi2.getName() + " is "
+ bmi2.getBMI() + " " + bmi2.getStatus());
}
}

Here is my error's

C:JavaChapter10>javac BMI.java
BMI.java:2: error: cannot find symbol
public static doulbe getBMI(double weight, double height){
^
symbol: class doulbe
location: class BMI
BMI.java:3: error: constructor BMI in class BMI cannot be applied to given types;
BMI bmi1 = new BMI("Doug Yang", 52, 245, 66);
^
required: no arguments
found: String,int,int,int
reason: actual and formal argument lists differ in length
BMI.java:4: error: cannot find symbol
System.out.println("The BMI for " + bmi1.getName() + " is "
^
symbol: method getName()
location: variable bmi1 of type BMI
BMI.java:5: error: method getBMI in class BMI cannot be applied to given types;
+ bmi1.getBMI() + " " + bmi1.getStatus());
^
required: double,double
found: no arguments
reason: actual and formal argument lists differ in length
BMI.java:5: error: cannot find symbol
+ bmi1.getBMI() + " " + bmi1.getStatus());
^
symbol: method getStatus()
location: variable bmi1 of type BMI
BMI.java:7: error: constructor BMI in class BMI cannot be applied to given types;
BMI bmi2 = new BMI("Kaye Wi", 34, 176, 61);
^
required: no arguments
found: String,int,int,int
reason: actual and formal argument lists differ in length
BMI.java:8: error: cannot find symbol
System.out.println("The BMI for " + bmi2.getName() + " is "
^
symbol: method getName()
location: variable bmi2 of type BMI
BMI.java:9: error: method getBMI in class BMI cannot be applied to given types;
+ bmi2.getBMI() + " " + bmi2.getStatus());
^
required: double,double
found: no arguments
reason: actual and formal argument lists differ in length
BMI.java:9: error: cannot find symbol
+ bmi2.getBMI() + " " + bmi2.getStatus());
^
symbol: method getStatus()
location: variable bmi2 of type BMI
9 errors

Explanation / Answer

Below is the solution of the above problem:

In this problem the BMI class cannot create a self object.

Below is corect way to use BMI class and the mainBMI class.

BMI.java:

//BMI class
public class BMI {
   private String name;
   private int age;
   private double weight;   // In pounds
   private double height;   // In inches
   //static variable to access direct without reating object
   public static final double KILOGRAMS_PER_POUND = 0.45359237;
   public static final double METERS_PER_INCH = 0.0254;
   public static final int INCH_PER_FOOT = 12;

   //BMI default constructor with name,age,weight and height parameter
   public BMI(String name, int age, double weight, double height) {
       this.name = name;
       this.age = age;
       this.height = height;
       this.weight = weight;
   }

   //getBMI() method that calculate the the bmi value and return
   public double getBMI() {
       double bmi = weight * KILOGRAMS_PER_POUND /
           ((height * METERS_PER_INCH) * (height * METERS_PER_INCH));
       return Math.round(bmi * 100) / 100.0;
   }

   //getStatus() method that status of the bmi
   public String getStatus() {
       double bmi = getBMI();
       if (bmi < 18.5)
           return "Underweight";
       else if (bmi < 25)
           return "Normal";
       else if (bmi < 30)
           return "Overweight";
       else
           return "Obese";
   }

   //getter method for the name,age,weight and height
   public String getName() {
       return name;
   }

   public int getAge() {
       return age;
   }

   public double getWeight() {
       return weight;
   }
  
   public double getHeight() {
       return height;
   }
}

mainBMI.java:

//main class that will display the calculated BMI value
public class mainBMI {
   public static void main(String[] args) {
       //BMI class of bmi1 object that has default contructor that take name,age,height,weight value
       BMI bmi1 = new BMI("Doug Yang", 52, 245, 66);
       //prints the MBI value using the bmi1 object calls getName(),getBMI() and getStatus() method of BMI class
       System.out.println("The BMI for " + bmi1.getName() + " is " + bmi1.getBMI() + " " + bmi1.getStatus());

       //prints the MBI value using the bmi1 object calls getName(),getBMI() and getStatus() method of BMI class
       BMI bmi2 = new BMI("Kaye Wi", 34, 176, 61);
       System.out.println("The BMI for " + bmi2.getName() + " is " + bmi2.getBMI() + " " + bmi2.getStatus());
   }
}

sample output:

The BMI for Doug Yang is 39.54 Obese
The BMI for Kaye Wi is 33.25 Obese