// Helene Martin, CSE 142 // This program computes two people's body mass indexes and // displays their weight status. // NOTE: this is the Chapter 4 case study import java.util.*; // for Scanner public class BMICalculator { public static void main(String[] args) { printIntroduction(); Scanner console = new Scanner(System.in); double bmi = getBMI(console); double bmi2 = getBMI(console); printResults(bmi, bmi2); } // introduces 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(); } // prompts for a person's weight and height // returns that person's body mass index 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(height, weight); System.out.println(); return bmi; } // calculates body mass index based on weight (lbs) and height (in) public static double bmiFor(double weight, double height) { return 703 * (weight / Math.pow(height, 2)); } // prints each person's bmi and weight class public static void printResults(double bmi, double bmi2) { System.out.println("Person 1 BMI = " + bmi); printWeightClass(bmi); System.out.println("Person 2 BMI = " + bmi2); printWeightClass(bmi2); } // prints a weight class based off a given bmi public static void printWeightClass(double bmi) { if (bmi < 18.5) { System.out.println("underweight"); } else if (bmi < 25) { System.out.println("normal"); } else if (bmi < 30) { System.out.println("overweight"); } else { System.out.println("obese"); } } }