

Absolute Java 

Authors:  Walter Savitch ,kenrick Mock  Chapter:  Getting Started 
ISBN:  9780132830317  Exercise:  Programming Projects 
Edition:  5  Question:  1 
One way to measure the amount of energy that is expended during exercise is to use metabolic equivalents (MET). Here are some METS for various activities: Running 6 MPH: 10 METS
Basketball: 8 METS
Sleeping: 1 MET
The number of calories burned per minute may be estimated using the following formula:
in kilograms
Write a program that calculates and outputs the total number of calories burned for a 150pound person who runs 6 MPH for 30 minutes, plays basketball for 30 minutes, and then sleeps for 6 hours. One kilogram is equal to 2.2 pounds.
Program:
// CaloriesCalculator.java
public class CaloriesCalculator
{
public static final double KILOGRAMS_PER_POUND = 2.2;
public static final int RUNNING_METS = 10;
public static final int BASKETBALL_METS = 8;
public static final int SLEEPING_METS = 1;
public static void main(String[] args)
{
double weightInKilograms = 150 / KILOGRAMS_PER_POUND;
double runningTimeInMinutes = 30;
double basketballTimeInMinutes = 30;
double sleepintTimeInMinutes = 6 * 60;
double caloriesBurnedForRunning = 0.0175
* RUNNING_METS * weightInKilograms
* runningTimeInMinutes;
double caloriesBurnedForBasketball = 0.0175
* BASKETBALL_METS * weightInKilograms
* basketballTimeInMinutes;
double caloriesBurnedForSleeping = 0.0175
* SLEEPING_METS * weightInKilograms
* sleepintTimeInMinutes;
double totalCaloriesBurned = caloriesBurnedForRunning
+ caloriesBurnedForBasketball
+ caloriesBurnedForSleeping;
System.out.println(
"Number of calories burned for running: "
+ caloriesBurnedForRunning);
System.out.println(
"Number of calories burned for basketball: "
+ caloriesBurnedForBasketball);
System.out.println(
"Number of calories burned for sleeping: "
+ caloriesBurnedForSleeping);
System.out.println(
"\nTotal number of calories burned per minute: "
+ totalCaloriesBurned);
}
}
Output:
Number of calories burned for running: 357.95454545454544
Number of calories burned for basketball: 286.3636363636364
Number of calories burned for sleeping: 429.5454545454545
Total number of calories burned per minute: 1073.8636363636363