// CSE 142, Summer 2008 (Marty Stepp) // This program computes the body mass index (BMI) of two people // and compares the two to find the difference in BMI. import java.util.*; public class BMI { public static void main(String[] args) { Scanner console = new Scanner(System.in); double bmi1 = person(console); double bmi2 = person(console); results(bmi1, bmi2); } // Prompts for the height/weight of a single person, // and returns that person's body mass index. public static double person(Scanner console) { System.out.println("Enter next person's information:"); System.out.print("Height (in inches)? "); double height = console.nextDouble(); System.out.print("Weight (in pounds)? "); double weight = console.nextDouble(); // compute the bmi double bmi = weight / (height * height) * 703; return bmi; } // Outputs the overall results of each person's BMI and difference. public static void results(double bmi1, double bmi2) { System.out.println("Person #1 body mass index = " + bmi1); System.out.println("Person #2 body mass index = " + bmi2); System.out.println("Difference = " + Math.abs(bmi1 - bmi2)); } }