// Allison Obourn, CSE 142 // This structured program computes two people's body mass index and // displays their weight status. import java.util.*; public class BMICalculator { public static void main(String[] args) { intro(); Scanner console = new Scanner(System.in); double bmi = processPerson(console); double bmi2 = processPerson(console); displayResults(bmi, bmi2); } // prints each person's bmi and weight class public static void displayResults(double bmi, double bmi2) { System.out.println("Person 1 BMI = " + bmi); printCategory(bmi); System.out.println("Person 2 BMI = " + bmi2); printCategory(bmi2); } // prints an introduction for the program. public static void intro() { 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 and returns the bmi class based on a // chart published by the Centers for Disease Control and Prevention public static void printCategory(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"); } } // prompts for height and weight, calculates and returns // body mass index 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(); double bmi = bmi(height, weight); System.out.println(); return bmi; } // calculates and returns body mass index based on weight and height public static double bmi(double height, double weight) { return weight / Math.pow(height, 2) * 703; } }