BMI = WeightInPounds*703/HeightInInches*HeightInInches or BMI = WeightInKilogram
ID: 3720502 • Letter: B
Question
BMI = WeightInPounds*703/HeightInInches*HeightInInches
or
BMI = WeightInKilograms/HeightinMeters*HeightInMeters
(In JAVA with comments) Create a BMI calculator application that reads the user’s weight in pounds and height in inches (or, if you prefer, the user’s weight in kilograms and height in meters), then calculates and displays the user’s body mass index. Also, the application should display the following information from the Department of Health and Human Services/National Institutes of Health so the user can evaluate his/her BMI:
BMI values
Underweight: less than 18.5
Overweight: between 25 and 29.9
Obese: 30 or greater
Explanation / Answer
BMICalculation.java
import java.util.Scanner;
public class BMICalculation {
/*
* Creating an Scanner class object which is used to get the inputs
* entered by the user
*/
static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
//callin the methods
int weight = getWeight();
int height = calInches();
double bmi = calcBMI(weight, height);
showResults(weight, height, bmi);
}
//This method will display the results
private static void showResults(int weight, int height, double bmi) {
String status = null;
//Based on the bmi value the corresponding block will be executed.
if (bmi < 18.5) {
status = "Your Weight Status is Under Weight";
} else if (bmi >= 18.5 && bmi <= 24.9) {
status = "Your Weight Status is Normal";
} else if (bmi >= 25.0 && bmi <= 29.9) {
status = "Your Weight Status is OverWeight";
} else if (bmi >= 30) {
status = "Your Weight Status is Obese";
}
System.out.println("Your Weight :" + weight);
System.out.println("Your Height :" + height);
System.out.printf("Your BMI value is :%.2f ", bmi);
System.out.println(status);
}
//This method will calculate the bmi value
private static double calcBMI(int weight, int height) {
//Calculating BMI and returning it to the caller
return ((double) weight / (height * height)) * 703;
}
//This method will get the weight entered by the user
private static int getWeight() {
System.out.print("Enter the Weight (in pounds):");
return sc.nextInt();
}
//This method will get the height entered by the user
private static int calInches() {
int inches;
System.out.print("Enter height in inches :");
inches = sc.nextInt();
return inches;
}
}
_________________
Output:
Enter the Weight (in pounds):170
Enter height in inches :66
Your Weight :170
Your Height :66
Your BMI value is :27.44
Your Weight Status is OverWeight
___________Thank You
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.