// Allison Obourn
// CS& 141, WInter 2021
// Lecture 6

// This program prompts two users for their height, weight, age and gender
// and computes a basal metabolic rate for each of them.
// It outputs this rate and whether it is high, moderate or low.

import java.util.*;

public class Bmr {
   public static void main(String[] args) {
      Scanner input = new Scanner(System.in);
      intro();
      
      double bmr = getData(input);      
      double bmr2 = getData(input);   

      System.out.println("Person #1 basal metabolic rate = " + round1(bmr));
      burnRate(bmr);
      System.out.println("Person #2 basal metabolic rate = " + round1(bmr2));
      burnRate(bmr2);
   }
   
   // takes a real number as a parameter and returns that number rounded to one 
   // digit after the decimal point
   public static double round1(double number) {
      return Math.round(number * 10) / 10.0;
   }
   
   // prints an introduction for the program.
   public static void intro() {
      System.out.println("This program reads data for two");
      System.out.println("people and computes their basal");
      System.out.println("metabolic rate and burn rate.");
      System.out.println();
   }
   
   // prompts the user to type in a height,  weight, age and gender,
   // then calculates and returns the basal metabolic rate
   public static double getData(Scanner input) {
      System.out.println("Enter next person's information:");
      System.out.print("height (in inches)? ");
      double height = input.nextDouble();
      
      System.out.print("weight (in pounds)? ");
      double weight = input.nextDouble();
      
      System.out.print("age (in years)? ");
      double age = input.nextDouble();
      
      System.out.print("gender (enter 1 for male or 2 for female)? ");
      int gender = input.nextInt();
      System.out.println();
      
      double bmr = computeBmr(weight, height, age, gender);
      return bmr;
   }
   
   // calculates and prints the whether the passed in bmr
   // is low, moderate or high
   public static void burnRate(double bmr) {
      if(bmr < 1200) {
         System.out.print("low");
      } else if(bmr < 2000) {
         System.out.print("moderate");
      } else {
         System.out.print("high");
      }
      System.out.println(" resting burn rate");
   }
   
   // takes a height in inches, weight in pounds, age in years and gender
   // (1 for male, 2 for female) and calculates and returns the basal metabolic
   // rate for a person with those characteristics using the base formula
   // 4.54545 x weight + 15.875 x height + 5 x age and adding 5 for men and
   // subtracting 161 for women
   public static double computeBmr(double weight, double height, double age, int gender) {
      double bmr = 4.54545 * weight + 15.875 * height - 5 * age;
      if(gender == 1) {
         bmr += 5;
      } else  {
         bmr -= 161;
      }
      return bmr;
   }
}