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

Write the same program above using classes, methods and constructors. Create a c

ID: 3816841 • Letter: W

Question

Write the same program above using classes, methods and constructors. Create a class called WH with two instance variables height and weight and a constructor to initialize weight and height. Include two methods: One called ratio to return ratio of weight/height (does not take any arguments) the second called message that does not return anything (void) but takes in a single double argument "ratio" form first method and prints the following: if the ratio is less than 2.1, tell the user "his weight height ratio is normal" if the ratio is less than 2.3, tell the user they are slightly above average if the ratio is less than 2.5, tell the user they need to lose 5% percent of their weight" if the ratio is equal to or higher than 2.5, tell the user they need to lose more than 5% of their weight" Include the class in a main class called Health Demo (use same name for project name in Net Beans) in main class create four objects with the following weights and heights Run program and print output:

Explanation / Answer

HealthDemo.java

public class HealthDemo {

  
   public static void main(String[] args) {
       WH w1 = new WH(145, 72);
       w1.message(w1.ratio());
       WH w2 = new WH(163, 72);
       w2.message(w2.ratio());
       WH w3 = new WH(165, 72);
       w3.message(w3.ratio());
       WH w4 = new WH(185, 72);
       w4.message(w4.ratio());
      
   }

}

WH.java


public class WH {
   private int height, weight;
   public WH(int weight, int height){
       this.height = height;
       this.weight= weight;
   }
   public double ratio() {
       return weight/(double)height;
   }
   public void message(double ratio){
       System.out.format("Ration is %.3f ", ratio);
       if(ratio < 2.1){
           System.out.println("Weight and Height ratio is normal");
       }
       else if(ratio >= 2.1 && ratio <2.3){
           System.out.println("Weight and Height ratio is slightly above average");
       }
       else if(ratio >= 2.3 && ratio <2.5){
           System.out.println("Need to lost 5% percent of weight");
       }
       else{
           System.out.println("Need to lost more than 5% percent of weight");
       }
   }
}

Output:

Ration is 2.014
Weight and Height ratio is normal
Ration is 2.264
Weight and Height ratio is slightly above average
Ration is 2.292
Weight and Height ratio is slightly above average
Ration is 2.569
Need to lost more than 5% percent of weight