In: Computer Science
Part 2: BasalMetabolicRate Write a Java program that estimates the number of calories your body needs to maintain your weight if you do no exercise. This is called your BMR (or Basal Metabolic Rate) and can be calculated with the Harris-Benedict equation. The calories needed for a woman to maintain her weight is: BMR (calories) = 655 + (4.35 * weight in pounds) + (4.7 * height in inches) - (4.7 * age in years) The calories needed for a man to maintain his weight is: BMR (calories) = 66 + (6.23 * weight in pounds) + (12.7 * height in inches) - (6.8 * age in years) Write a program that allows the user to input his or her weight in pounds, height in inches, and age in years. Your program should output two things: 1) The number of calories needed to maintain one's weight for both a woman and a man of the same input weight, height and age AND 2) The number of chocolate bars that should be consumed to maintain this amount of calories (a typical chocolate bar contains about 230 calories) Here is a sample transaction with the user: Please enter your weight (lb): 160 Please enter your height (in): 70 Please enter your age: 40 BMR (female):1492 calories BMR (male) : 1680 calories If you are female, you need to consume 6.5 chocolate bars to maintain weight. If you are male, you need to consume 7.3 chocolate bars to maintain weight.
import java.util.Scanner;
public class BMR {
public static void main(String[] args) {
Scanner scan = new
Scanner(System.in);
// Take user input
System.out.print("Please enter your
weight (lb): ");
double weight =
Double.parseDouble(scan.nextLine());
System.out.print("Please enter your
height (in): ");
double height =
Double.parseDouble(scan.nextLine());
System.out.print("Please enter your
age: ");
int age =
Integer.parseInt(scan.nextLine());
double bmr_female, bmr_male = 0;
// Calculate bmr for both male
and female and print it
bmr_female = 655 + (4.35 * weight)
+ (4.7 * height) - (4.7 * age);
bmr_male = 66 + (6.23 * weight) +
(12.7 * height) - (6.8 * age);
System.out.println("\nBMR
(female): " + String.format("%.2f", bmr_female) + "
calories");
System.out.println("BMR (male): " +
String.format("%.2f", bmr_male) + " calories");
// Calculate number of choco
bars for both male and female and print it
double choco_bar_female =
bmr_female / 230;
double choco_bar_male = bmr_male /
230;
System.out.println("If you are
female, you need to consume " + String.format("%.1f",
choco_bar_female)
+ " chocolate bars to maintain weight.");
System.out.println("If you are
male, you need to consume " + String.format("%.1f",
choco_bar_male)
+ " chocolate bars to maintain weight.");
}
}
OUTPUT