// A program that displays the body mass index of a person.
public class BodyMassIndex
{
public static void main (String [] args)
{
Person girl
= new Person ();
girl.readData
();
girl.calculateBMI
();
girl.displayBMI
();
} // main method
} // class BodyMassIndex
// A class that computes and then displays the body mass index of a
person.
class Person
{
private String name;
private int height, weight, bmi;
public void readData ()
{
try
{
BufferedReader stdin = new BufferedReader (new InputStreamReader (System.in));
System.out.print ("Name: ");
name = stdin.readLine ();
System.out.print ("Height in Inches: ");
height = Integer.parseInt (stdin.readLine ());
System.out.print ("Weight in Pounds: ");
weight = Integer.parseInt (stdin.readLine ());
}
catch (IOException
e) { System.out.println ("I/O error");}
catch (NumberFormatException
ex) { System.out.println ("Number format error.");}
} // readData
public void calculateBMI ()
{
bmi = (705 *
weight) / (height * height);
} // calculateBMI
// A method that computes and displays the
body mass index.
public void displayBMI ()
{
System.out.println
(name + "'s body mass index is " + bmi);
} // displayBMI
} // class Person