ABSOLUTE JAVA

ABSOLUTE JAVA

Authors: Walter Savitch ,Kenrick Mock
ISBN: 9780132830317
Edition: 5
Chapter: getting started
Exercise: Programming Projects
Question: 1

Question by : anonymous

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 150-pound 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.


Answer by : SRNTR

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
0 0

Discussions

Post the discussion improve the above solution.