// This program computes 2 persons' body mass index (BMI). // This larger example uses more parameters and returns. import java.util.*; // for Scanner public class BMI2 { public static void main(String[] args) { giveIntro(); Scanner console = new Scanner(System.in); double bmi1 = processPerson(console); double bmi2 = processPerson(console); System.out.println("Person #1 body mass index = " + bmi1); System.out.println("Person #2 body mass index = " + bmi2); System.out.println("difference = " + (bmi1 - bmi2)); } public static void giveIntro() { System.out.println("This program reads in data for two people"); System.out.println("and computes their body mass index (BMI)"); System.out.println("and weight status."); System.out.println(); } // prompts for one person's statistics, returning the BMI public static double processPerson(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(); System.out.println(); double bmi = getBMI(height, weight); return bmi; } // this method contains the body mass index formula for converting the // given height (in inches) and weight (in pounds) into a BMI public static double getBMI(double height, double weight) { double bmi = weight / (height * height) * 703; return bmi; } }