Body Mass Index Calculator
I am working on a bmi calculator that is a revision of an example program in my textbook. The program lets user enter weight (in pounds) and height (in feet and inches) and then calculates bmi. Weight is converted to kilograms and height is converted to meters.
I have this so far:
Code:
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\n" , bmi);
}
}
Only difference from example in the book is they used height in inches from start, everything else is same. I am getting large numbers like 946 for bmi when it should be like 20.95. Problem may be in conversion from feet to inches and then inches to meters. Anybody see what I am missing.