import java.io.*;
import java.text.*;
import java.util.*;
class BodyMassIndex
{
public static void main (String [] args)
{
Person person
= new Person ();
person.getData
();
person.displayData
();
} // method main
} // class BodyMassIndex
// Class that uses a string tokenizer to get body mass index data.
class Person
{
private String name;
private double weight, height, heightFeet,
heightInches;
// Read a string of data from the keyboard
and use a string tokenizer to separate it into parts.
public void getData ()
{
String dataString;
StringTokenizer
tokenizer;
BufferedReader
stdin = new BufferedReader (new InputStreamReader (System.in));
try
{
System.out.println ("Enter name, weight in pounds, height in feet, and
height in inches ");
System.out.println (" on a single line, separated by spaces. ");
dataString = stdin.readLine ();
tokenizer = new StringTokenizer (dataString);
name = tokenizer.nextToken ();
weight = Double.parseDouble (tokenizer.nextToken());
heightFeet = Double.parseDouble (tokenizer.nextToken ());
heightInches = Double.parseDouble (tokenizer.nextToken ());
height = 12 * heightFeet + heightInches;
}catch (NumberFormatException
e){System.out.println ("Number Format Exception");}
catch (IOException
e){System.out.println ("IO Exception");}
} // method getData
// Compute the body mass index and display
it on the screen.
public void displayData ()
{
double bmi =
calculateBMI();
System.out.print
(name + "'s body mass index is ");
System.out.println (decimals
(bmi));
} // method displayData
// Calculate the body mass index using English
units.
private double calculateBMI ()
{
double bmi;
bmi = (705 *
weight) / (height * height);
return bmi;
} // calculateBMI
// Format a double for string output with
two decimal places.
private String decimals (double number)
{
DecimalFormat
decFor = new DecimalFormat ();
decFor.setMaximumFractionDigits
(2);
decFor.setMinimumFractionDigits
(2);
return decFor.format
(number);
} // decimals
} //class Person