// Tyler Rigsby, CSE 142 // Calcaluates the BMI of two people and reports statistics about them import java.util.*; public class BMI { public static void main(String[] args) { Scanner console = new Scanner(System.in); intro(); double bmi1 = getBMI(console); double bmi2 = getBMI(console); reportResults(bmi1, bmi2); } // handles reporting the results of the two people with their // specified BMIs. public static void reportResults(double bmi1, double bmi2) { System.out.println("Person 1's BMI is: " + round1(bmi1)); getStatus(bmi1); System.out.println("Person 2's BMI is: " + round1(bmi2)); getStatus(bmi2); } // prints the introduction to the program public static void intro() { System.out.println("This program reads in data for two people and"); System.out.println("computes their body mass index (BMI)"); System.out.println(); } // prints the person's status given their bmi public static void getStatus(double bmi) { if (bmi < 18.5) { System.out.println("underweight"); } else if (bmi < 25.0) { System.out.println("normal"); } else if (bmi < 30.0) { System.out.println("overweight"); } else { // if (bmi >= 30.0) { System.out.println("obese"); } } // prompts and reads the height and weight of a person and // returns their BMI public static double getBMI(Scanner console) { System.out.println("Enter next person's information"); System.out.print("Enter height (in inches): "); double height = console.nextDouble(); System.out.print("Enter weight (in pounds): "); double weight = console.nextDouble(); // careful--don't round this, or you may use it incorrectly later return BMIFor(weight, height); } // Returns the BMI for a given weight and height based on the scientific formula public static double BMIFor(double weight, double height) { return 703 * weight / (height * height); } // returns the specified value rounded to one decimal place public static double round1(double val) { return Math.round(val * 10) / 10.0; } }