// This program computes two people's body mass index (BMI) and compares them. // This version also uses more parameters and return values. import java.util.*; // so that I can use Scanner public class BMI { public static void main(String[] args) { introduction(); Scanner console = new Scanner(System.in); processTwoPeople(console); } // optional method to process two people. public static void processTwoPeople(Scanner console) { double bmi1 = processPerson(console); double bmi2 = processPerson(console); // report overall results System.out.println("Person #1 body mass index = " + bmi1); System.out.println("Person #2 body mass index = " + bmi2); double difference = Math.abs(bmi1 - bmi2); System.out.println("Difference = " + difference); } // prints a welcome message explaining the program public static void introduction() { 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(); } // reads information for one person, computes their BMI, and returns it 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; } // Computes a person's body mass index based on their height and weight // and returns the BMI as its result. public static double getBMI(double height, double weight) { double bmi = weight / (height * height) * 703; return bmi; } }