Advertisement
mbazs

Calc BMI

Nov 21st, 2018
471
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.50 KB | None | 0 0
  1.     public static void calculateBMI(String name, String[] names, int[] weight, double[] height) {
  2.  
  3.         /*
  4.          * This method should be changed
  5.          *
  6.          * Calculate and print out BMI (body mass index) for each user
  7.          * BMI = weight in kg/height in meter * height in meter
  8.          *
  9.          * Check if the user is Underweight, Normal, Overweightor or Obese based on the BMI
  10.          * Underweight, when bmi is less than 18.5
  11.          * Normal, when bmi is between 18.5 and 24.9
  12.          * Overweight, when bmi is between 25 and 29.9
  13.          * Obese, when bmi is more than 30
  14.          *
  15.          *
  16.          * To check if a string is equal to another string use:
  17.          * stringVariable.equalsIgnoreCase(anotherStringVariable)
  18.          *
  19.          */
  20.         //Your code starts here
  21.                
  22.                 for (int i = 0; i < names.length; ++i) {
  23.                     if (name.equalsIgnoreCase(names[i])) {
  24.                         double bmi = weight[i] / (height[i] * height[i]);
  25.                         String bodyType = "";
  26.                         if (bmi < 18.5) {
  27.                             bodyType = "underweight";
  28.                         } else if (bmi < 25) {
  29.                             bodyType = "normal";
  30.                         } else if (bmi < 30) {
  31.                             bodyType = "overweight";
  32.                         } else {
  33.                             bodyType = "obese";
  34.                         }
  35.                         System.out.println(name + " is " + bodyType + ", BMI index = " + bmi);
  36.                     }
  37.                 }
  38.            
  39.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement