// Helene Martin, Garfield High School (from Stuart Reges and Marty Stepp)
// This program computes two people's body mass index (BMI) and
// compares them.  The code uses parameters, returns, and Scanner.

import java.util.*; 

public class BMI {
	public static void main(String[] args) {
		  System.out.println("Welcome to my super BMI calculator.");
	     System.out.println("It'll read data for two people and compute their body mass index and weight status.\n");
        
        Scanner console = new Scanner(System.in);
        double bmi1 = person(console);
        double bmi2 = person(console);
        
        // report overall results
        report(1, bmi1);
        report(2, bmi2);
        System.out.println("Difference = " + round2(Math.abs(bmi1 - bmi2)));
    }
    
    // prints a welcome message explaining the program
    public static void introduction() {
        System.out.println("This program reads data for two people and");
        System.out.println("computes their body mass index (BMI).");
        System.out.println();
    }

    // Reads information for one person, then computes and returns their BMI.
    public static double person(Scanner console) {
        System.out.println("Enter a 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 bodyMass = bmi(height, weight);
        return bodyMass;
    }
    
    // Computes and returns a person's BMI for the given height and weight.
    public static double bmi(double height, double weight) {
        double result = weight / (height * height) * 703;
        return result;
    }

    // Outputs information about a person's BMI and weight status.
    public static void report(int number, double bmi) {
        System.out.println("Person " + number + " BMI = " + round2(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");
        }
    }
	 
	 // returns the value n rounded to two decimal places
    public static double round2(double n) {
        double result = 100.0 * n;
        result = Math.round(result);
        result = result / 100;
        return result;
    }

}

