Solution for calculating METS...

Page 1 of 1

4 Replies - 10723 Views - Last Post: 30 July 2013 - 10:09 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=285837&amp;s=14866a26414d3cc90d5fa43b393f3fc5&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

#1 theNoob

Reputation: 3
• Posts: 66
• Joined: 14-July 12

Solution for calculating METS...

Posted 14 July 2012 - 10:03 PM

Hey Guys, this is the question that I have worked out however not sure if the answer is correct.

I don't get any errors but would like an expert's view. Thank you in advanced.

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
Sleeping: 1 MET

The number of calories burned per minute may be estimated using the following
formula:
Calories/Minute = 0.0175 * MET * Weight 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.

```
private static void Q1()
{
int runningMET = 10;	//Defined values in txt book
int bBallMET = 8;		//Defined values in txt book
int sleepingMET = 1;	//Defined values in txt book

double weight = 150/2.2;		//Converting pounds into Kilo.
double constFactor = 0.0175;

double calRun = calcMet(constFactor, runningMET, weight, 30);
double calBball = calcMet(constFactor, bBallMET, weight, 30);
double calSleep = calcMet(constFactor, sleepingMET, weight, 6*60);

System.out.println("Question 1 Solution");
System.out.println("Total cals burned " + (calRun + calBball + calSleep));
System.out.println();
}

private static double calcMet(double constFactor, int MET, double weight, int time)
{
return constFactor * MET * weight * time;
}

```

The output for this program is:

Question 1 Solution
Total cals burned 1073.8636363636363

Is This A Good Question/Topic? 0

Replies To: Solution for calculating METS...

#2 GregBrannon

• D.I.C Lover

Reputation: 2245
• Posts: 5,330
• Joined: 10-September 10

Re: Solution for calculating METS...

Posted 14 July 2012 - 10:12 PM

#3 theNoob

Reputation: 3
• Posts: 66
• Joined: 14-July 12

Re: Solution for calculating METS...

Posted 14 July 2012 - 10:16 PM

GregBrannon, on 14 July 2012 - 10:12 PM, said:

I just wanted to double check to ensure the output correct.

#4 x68zeppelin80x

Reputation: 130
• Posts: 576
• Joined: 07-March 09

Re: Solution for calculating METS...

Posted 14 July 2012 - 10:22 PM

If you have a constant, you should define it as one:
```final static double FACTOR = 0.0175;
static double weight = 150/2.2;

private static void Q1() {
int runningMET = 10;	//Defined values in txt book
int bBallMET = 8;		//Defined values in txt book
int sleepingMET = 1;	//Defined values in txt book

double calRun = calcMet(runningMET, 30);
double calBball = calcMet(bBallMET, 30);
double calSleep = calcMet(sleepingMET, 6*60);

System.out.println("Question 1 Solution");
System.out.println("Total cals burned " + (calRun + calBball + calSleep));
System.out.println();
}

private static double calcMet(int MET, int time) {
return FACTOR * MET * weight * time;
}

```

This post has been edited by x68zeppelin80x: 14 July 2012 - 10:23 PM

#5 tigran_tal

Reputation: 0
• Posts: 8
• Joined: 30-July 13

Re: Solution for calculating METS...

Posted 30 July 2013 - 10:09 PM

I just wrote a solution to this with using console output. It also gives exact same answer. However, i cant beleive 6 hours of sleeping will burn 429.55 Cals..Am I doing something wrong here? My code :
```import java.util.*;
public class Calor_count {

public static final double RUNNINGMET = 10;
public static final double BASKETBALLMET = 8;
public static final double SLEEPINGMET = 1;
public static final double FACTOR = 0.0175 ;

public static void main(String[] args) {

double weightkg = weightConverter(pounds);

double runningm = minuteCalc(runningh);
double runningCal = calC(RUNNINGMET,runningm,weightkg);

double bBallm = minuteCalc(bBallh);

double sleepingm = minuteCalc(sleepingh);
double sleepingCal = calC(SLEEPINGMET,sleepingm,weightkg);

double totalCal = runningCal + bBallCal + sleepingCal ;
System.out.printf("%6.2f",totalCal);
}

static double calC(double MET, double minutes, double weightkg){

return FACTOR  * MET * minutes * weightkg;
}

static double weightConverter(double pounds){

double kilos = pounds/2.2 ;
return kilos ;
}

static double minuteCalc(double hours ){

double minutes = hours * 60 ;
return minutes;
}

}

```