Inactive Tutor answered 02/19/19
What are the units of measurement for weight and height?
Is the weight in pounds or kilograms?
Is the height in inches, feet and inches, or meters and centimeters?
Module 1: displays a prompt for input and reads in the values for height and weight, validating as needed
Module 2: converts these measures to either metric or english measures for computation purposes
Module 3: uses the formula to calculate the BMI
Module 4: OUTPUT: displays and echoes the input and the BMI; Must you Perhaps display a supplementary message based on the BMI result regarding obesity, normal, borderline overweight, overweight, etc.
EX. BMI is 42. Morbidly Obese
BMI is 25. NORMAL
=====================================================================
Here's some code:
import java.io.*;
class BMI
{
// uses english measurements: weight in pounds, height in inches
private double weight;
private double height;
//constructor
BMI ( double h, double w)
{
weight = w; height = h;
}
public double GetHeight() { return(height); }
public double GetWeight() { return(weight); }
public double CalculateBMI() { return(weight*703/(height*height)); }
public double PromptForDouble( String promptMsg) throws IOException
{
double dblNum=0;
String inbuff=null;
Console console = System.console();
do
{
System.out.print(promptMsg);
inbuff = console.readLine();
dblNum = Double.parseDouble(inbuff);
} while (dblNum<=0);
return(dblNum);
} //PromptForDouble
public static void main( String args[])
{
double hFt=0,hIn=0,w=0;
BMI dummyInput = new BMI(0,0);
try
{
System.out.println(" Please input the height in feet and inches. For example \n" +
" EX. 5 ft 3 in : input 5 then press enter; then input 3 and press enter \n");
hFt = dummyInput.PromptForDouble(" feet :> ");
hIn = dummyInput.PromptForDouble(" inches :> ");
w = dummyInput.PromptForDouble(" Please input the weight in pounds :>");
}
catch (IOException ex) { System.out.println(" input exception has occurred"); }
BMI myBMI = new BMI(hFt*12+hIn,w); //converts feet and inches to just inches
System.out.println("**********************************************************");
System.out.println(" Weight is " + myBMI.GetWeight() );
System.out.println(" Height in inches is " + myBMI.GetHeight() );
System.out.println(" BMI is " + myBMI.CalculateBMI() );
System.out.println("************************************************************");
} //main
}//class