214k views
5 votes
The following equation estimates the average calories burned for a person when exercising, which is based on a scientific journal article (source):

Calories = ( (Age x 0.2757) + (Weight x 0.03295) + (Heart Rate x 1.0781) — 75.4991 ) x Time / 8.368

Write a program using inputs age (years), weight (pounds), heart rate (beats per minute), and time (minutes), respectively. Output the average calories burned for a person.

Output each floating-point value with two digits after the decimal point, which can be achieved as follows:
System.out.printf("%.2f", yourValue);

Ex: If the input is:

49 155 148 60
the output is:

Calories: 736.21 calories

1 Answer

3 votes

Here's a Java program that implements the equation:

import java.util.Scanner;

public class Main {

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

System.out.print("Enter age (years): ");

double age = scanner.nextDouble();

System.out.print("Enter weight (pounds): ");

double weight = scanner.nextDouble();

System.out.print("Enter heart rate (beats per minute): ");

double heartRate = scanner.nextDouble();

System.out.print("Enter time (minutes): ");

double time = scanner.nextDouble();

double calories = ((age * 0.2757) + (weight * 0.03295) + (heartRate * 1.0781) - 75.4991) * time / 8.368;

System.out.printf("Calories: %.2f calories\\", calories);

}

}

User Spurra
by
8.7k points