Assignemnt #48: BMI Calculator with Categories
Code
/// Name: Sean Harrison
/// Period: 7
/// Program name: BMICalculator
/// File Name: BMICalculator.java
/// Date Finished: 10/28/2015
import java.util.Scanner;
public class BMICalculator
{
public static void main( String[] ags )
{
Scanner keyboard = new Scanner(System.in);
double ft, in, lbs, m, kg, bmi;
String bmiClass;
bmiClass = "null";
System.out.print( "Your height in feet: " );
ft = keyboard.nextDouble();
System.out.print( "Your height in inches: " );
in = keyboard.nextDouble();
m = ((ft * 12) + in) * 2.54 / 100;
System.out.print( "Your weight in pounds: " );
lbs = keyboard.nextDouble();
kg = lbs * .454;
bmi = kg / (m*m);
System.out.println( "Your BMI is " + bmi );
if (bmi <= 15.0)
{
bmiClass = "very severely underweight";
System.out.println( " BMI Category : " + bmiClass );
}
if ((bmi >= 15.0) && (bmi <= 16.0))
{
bmiClass = "severely underweight";
System.out.println( " BMI Category : " + bmiClass );
}
if ((bmi >= 16.1) && (bmi <= 18.4))
{
bmiClass = "underweight";
System.out.println( " BMI Category : " + bmiClass );
}
if ((bmi >= 18.5) && (bmi <= 24.9 ))
{
bmiClass = "normal weight";
System.out.println( " BMI Category : " + bmiClass );
}
if ((bmi >= 25) && (bmi <= 29.9))
{
bmiClass = "overweight";
System.out.println( " BMI Category : " + bmiClass );
}
if ((bmi >= 30.0) && (bmi <= 34.9))
{
bmiClass = "moderately obsese";
System.out.println( " BMI Category : " + bmiClass );
}
if ((bmi >= 35.0) && (bmi <= 39.9))
{
bmiClass = "severely obsese";
System.out.println( " BMI Category : " + bmiClass );
}
if (bmi >= 40.0)
{
bmiClass = "morbidly obese";
System.out.println( "BMI Category: " + bmiClass );
}
}
}
Picture of the output