4 Replies - 3502 Views - Last Post: 30 July 2013 - 10:09 PM Rate Topic: -----

#1 theNoob  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • 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
Basketball: 8 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  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2194
  • View blog
  • Posts: 5,222
  • Joined: 10-September 10

Re: Solution for calculating METS...

Posted 14 July 2012 - 10:12 PM

You could check your answer with a calculator. What's your question about the code you've posted?
Was This Post Helpful? 0
  • +
  • -

#3 theNoob  Icon User is offline

  • D.I.C Head

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

Re: Solution for calculating METS...

Posted 14 July 2012 - 10:16 PM

View PostGregBrannon, on 14 July 2012 - 10:12 PM, said:

You could check your answer with a calculator. What's your question about the code you've posted?



I just wanted to double check to ensure the output correct.
Was This Post Helpful? 0
  • +
  • -

#4 x68zeppelin80x  Icon User is offline

  • D.I.C Addict

Reputation: 105
  • View blog
  • Posts: 508
  • 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

Was This Post Helpful? 0
  • +
  • -

#5 tigran_tal  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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) {
		
	Scanner readinginput = new Scanner(System.in);
	
	System.out.println("Please enter your weight in pounds");
	double pounds = readinginput.nextDouble();
	double weightkg = weightConverter(pounds);
	
	System.out.println("Please enter your running hours");
	double runningh = readinginput.nextDouble();
	double runningm = minuteCalc(runningh);
	double runningCal = calC(RUNNINGMET,runningm,weightkg);
	
	System.out.println("Please enter your basketball hours");
	double bBallh = readinginput.nextDouble();
	double bBallm = minuteCalc(bBallh);
	double bBallCal = calC(BASKETBALLMET,bBallm,weightkg);
	
	System.out.println("Please enter your sleepinghours");
	double sleepingh = readinginput.nextDouble();
	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;
   }
   
}




Was This Post Helpful? 0
  • +
  • -

Page 1 of 1