Body Mass Index Create a Java class that calculates BMI. Your program should hav
ID: 3758610 • Letter: B
Question
Body Mass Index
Create a Java class that calculates BMI. Your program should have the following fields:
name
height in meters
mass in kilograms
The BMI formula is as follows:
How BMI relates to fitness is specified in the following chart:
Your BMI class should have two general methods and a toString method. The first general method should calculate BMI and return it as a float. The second general method should accept a BMI as a parameter and return a string that is the category for that BMI from the table above.
Category BMI range (kg/m2) Very severely underweight less than 15 Severely underweight from 15.0 to 16.0 Underweight from 16.0 to 18.5 Normal (healthy weight) from 18.5 to 25 Overweight from 25 to 30 Obese Class I (Moderately obese) from 30 to 35 Obese Class II (Severely obese) from 35 to 40 Obese Class III (Very severely obese) over 40Explanation / Answer
import java.util.*;
public class ExerciseSix
{
//Attributes
private double weight, feet, inches;
final double kgPerPound = 0.45359237;
final double metPerInch = 0.0254;
//Constructors
public ExerciseSix()
{
Scanner reader = new Scanner(System.in);
System.out.println("Enter weight in pounds: ");
weight = reader.nextDouble();
System.out.println("Enter height in feet and inches: ");
feet = reader.nextDouble();
inches = reader.nextDouble();
}
//Methods
public void bodyMassIndex()
{
double wtInKilos = weight * kgPerPound;
double htInInches = ((feet / 12) + inches);
double htInMeters = htInInches * metPerInch;
double bmi = wtInKilos / (htInMeters * htInMeters);
System.out.printf("Your BMI is %5.2f " , bmi);
}
}