Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void calculateBMI(String name, String[] names, int[] weight, double[] height) {
- /*
- * This method should be changed
- *
- * Calculate and print out BMI (body mass index) for each user
- * BMI = weight in kg/height in meter * height in meter
- *
- * Check if the user is Underweight, Normal, Overweightor or Obese based on the BMI
- * Underweight, when bmi is less than 18.5
- * Normal, when bmi is between 18.5 and 24.9
- * Overweight, when bmi is between 25 and 29.9
- * Obese, when bmi is more than 30
- *
- *
- * To check if a string is equal to another string use:
- * stringVariable.equalsIgnoreCase(anotherStringVariable)
- *
- */
- //Your code starts here
- for (int i = 0; i < names.length; ++i) {
- if (name.equalsIgnoreCase(names[i])) {
- double bmi = weight[i] / (height[i] * height[i]);
- String bodyType = "";
- if (bmi < 18.5) {
- bodyType = "underweight";
- } else if (bmi < 25) {
- bodyType = "normal";
- } else if (bmi < 30) {
- bodyType = "overweight";
- } else {
- bodyType = "obese";
- }
- System.out.println(name + " is " + bodyType + ", BMI index = " + bmi);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement