Write a program to calculate calories burned based on age, weight, heart rate, and...

Check the final answer first, then review the worked steps.

Answer

Calories: 736.21 calories

Approach

Scanner scnr = new Scanner(System.in);
double age = scnr.nextDouble();
double weight = scnr.nextDouble();
double heartRate = scnr.nextDouble();
double time = scnr.nextDouble();
double calories = ((age 0.2017) + (weight 0.09036) + (heartRate 0.6309) - 55.0969) time / 4.184;
System.out.printf("Calories: %.2f calories\n", calories);

Step-by-step solution

  1. Import the Scanner class to read user input.
  2. Create a Scanner object to read the four input values: age, weight, heart rate, and time.
  3. Calculate calories using the standard formula for men: $Calories = ((Age \times 0.2017) + (Weight \times 0.09036) + (HeartRate \times 0.6309) - 55.0969) \times Time / 4.184$.
  4. Use System.out.printf("Calories: %.2f calories\n", calories); to format the output to two decimal places.