// Helene Martin, CSE 142 // Computes two people's body mass index and // displays their weight status. // Chapter 4 case study! import java.util.*; // for Scanner public class BMICalculator2 { public static void main(String[] args) { Scanner s = new Scanner(System.in); printIntroduction(); double bmi1 = getBMI(s); double bmi2 = getBMI(s); printResults(bmi1, 1); printResults(bmi2, 2); System.out.println("Difference: " + Math.abs(bmi1 - bmi2)); } // explains the program public static void printIntroduction() { System.out.println("This program reads in data for two people and"); System.out.println("computes their body mass index (BMI)"); System.out.println(); } // calculates bmi based on weight and height public static double bmiFor(double weight, double height) { return 703 * (weight / Math.pow(height, 2)); } // gets a person's weight and height, returns their bmi public static double getBMI(Scanner s) { System.out.println("Enter next person's information"); System.out.print("height (in inches): "); double height = s.nextDouble(); System.out.print("weight (in pounds): "); double weight = s.nextDouble(); double bmi = bmiFor(weight, height); return bmi; } // prints person's bmi to the console public static void printResults(double bmi, int person) { System.out.println("Person " + person + " BMI = " + bmi); String result = weightClass(bmi); System.out.println(result); } // converts bmi to a weight class public static String weightClass(double bmi) { if(bmi < 18.5) { return "underweight"; } else if(bmi < 25) { return "normal"; } else if(bmi < 30) { return "overweight"; } else { return "obese"; } } }