Sythe.Org Forums     Register     FAQ     Members List     Calendar     Mark Forums Read    
 
Sythe.Org Forums  
   Runescape Gold

Sythe.org — A Virtual Goods Trading Hub

Make real cash! buying and selling in-game items.

We have a no-scam policy.

You can make thousands playing your favourite games here at Sythe.org.

Just sign up an account and follow the rules!


Take me to

Runescape Markets

Other Game Markets

Support Center

Register an Account

Close
Diet Calculator
Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 01-21-2012, 11:02 AM
kmjt's Avatar
"In order to succeed, you must first be willing to fail."
kmjt Donor Sythe Verified User
 
Join Date: Aug 2009
Location: Canada
Posts: 8,548
St. Patrick's Day 2013 Heidy
Default Diet Calculator

Practicing for an intro to java class so I decided to make my own diet calculator. First the code then i'll explain..

Code:
// KMJT's Diet Calculator

import java.util.Scanner;

public class Diet 
{
	public static void main(String[] args)
	{
		Scanner keyboard = new Scanner(System.in);
		System.out.println("Enter your weight in pounds: ");
		
		double pounds = keyboard.nextInt();
		double kg = pounds*0.453592;
		
		System.out.println("\nEnter your bodyfat percentage: ");
		double bodyfat = keyboard.nextDouble();
		
		System.out.println("\nEnter your ACTIVITY LEVEL...");
		System.out.println("1.2 = Sedentary (Little or no exercise + desk job)");
		System.out.println("1.3-1.4 = Lightly Active (Little daily activity & light exercise 1-3 days a week)");
		System.out.println("1.5-1.6 = Moderately Active (Moderately active daily life & Moderate exercise 3-5 days a week)");
		System.out.println("1.7-1.8 = Very Active (Physically demanding lifestyle & Hard exercise or sports 6-7 days a week)");
		System.out.println("1.9-2.0 = Extremely Active (Hard daily exercise or sports and physical job)");
		
		double activity = keyboard.nextDouble();
		
		double lbm = (kg * (100 - bodyfat)) / 100;
		
		double bmr = (370 + (21.6 * lbm)) * activity;
		
		double bulk = bmr + (bmr*0.2);
		double cut = bmr - (bmr*0.2);
		
		System.out.println("Type \"1\" if you wish to gain weight otherwise type \"2\" if you wish to lose weight: ");
		int bulkorcut = keyboard.nextInt();
		System.out.println(bulkorcut);
		
		if (bulkorcut == 1)
		{
			System.out.println("To gain weight you must take in approximately " + bulk + " calories a day.");
		}
		
		else if (bulkorcut == 2)
		{
			System.out.println("To lose weight you must take in approximately " + cut + " calories a day.");
		}
		
		else
		{	
			System.out.println("You didn't type in 1 or 2. Restart program.");
		}	
	}
}

Basically I took all the formulas from THIS thread on bodybuilding.com.

Step by step this is how it works..

-Asks for the user's weight in pounds then automatically converts to kg.
-Asks for the user's bodyfat percentage.
-Asks for the user's activity level.
-Calculates user's LBM by using entered weight and bodyfat percentage.
-Uses Katch-McArdle forumla to calculate BMR.
-Multiplies BMR by activity level to aquire maintenance level.


Then the user can proceed from 2 choices..

-Calculating calorie intake to gain weight.
-Calculating calorie intake to lose weight.


These are calculated by either adding or subtracting 20% of the maintenance level calories.
Reply With Quote
  #2  
Old 01-21-2012, 11:57 PM
The Black Tux's Avatar
Only Skype: TBT_Sythe | Always Request a PM!
Java Programmers The Black Tux Donor Sythe Verified User
 
Join Date: Apr 2009
Location: Colombia
Posts: 5,799
Send a message via Skype™ to The Black Tux
Sythe Donations Bond Holder
Default Re: Diet Calculator

Nice, I'd suggest adding support for both KG and LB.

If user inputs 45(lb) it will be pounds, if the user includes kg anywhere in the text, you can skip the conversion part

Can't think of any other suggestion other than leaving a nice comment

Good joob... And do not forget the smile of the section
__________________
The Paypal Blacklist
1100+ Vouches - OMM Service
"It is hard to believe that a man is telling the truth when you know that you would lie if you were in his place."
OMM | MM of 2011 & 2012 | Most Helpful User of 2011 | Former OGV | Former CA | 2x Most Community-Involved MotM
Reply With Quote
  #3  
Old 01-23-2012, 05:45 AM
Forum Addict
 
Join Date: Jun 2010
Posts: 285
Default Re: Diet Calculator

Quote:
Originally Posted by kmjt View Post
Practicing for an intro to java class so I decided to make my own diet calculator. First the code then i'll explain..

Code:
// KMJT's Diet Calculator

import java.util.Scanner;

public class Diet 
{
	public static void main(String[] args)
	{
		Scanner keyboard = new Scanner(System.in);
		System.out.println("Enter your weight in pounds: ");
		
		double pounds = keyboard.nextInt();
		double kg = pounds*0.453592;
		
		System.out.println("\nEnter your bodyfat percentage: ");
		double bodyfat = keyboard.nextDouble();
		
		System.out.println("\nEnter your ACTIVITY LEVEL...");
		System.out.println("1.2 = Sedentary (Little or no exercise + desk job)");
		System.out.println("1.3-1.4 = Lightly Active (Little daily activity & light exercise 1-3 days a week)");
		System.out.println("1.5-1.6 = Moderately Active (Moderately active daily life & Moderate exercise 3-5 days a week)");
		System.out.println("1.7-1.8 = Very Active (Physically demanding lifestyle & Hard exercise or sports 6-7 days a week)");
		System.out.println("1.9-2.0 = Extremely Active (Hard daily exercise or sports and physical job)");
		
		double activity = keyboard.nextDouble();
		
		double lbm = (kg * (100 - bodyfat)) / 100;
		
		double bmr = (370 + (21.6 * lbm)) * activity;
		
		double bulk = bmr + (bmr*0.2);
		double cut = bmr - (bmr*0.2);
		
		System.out.println("Type \"1\" if you wish to gain weight otherwise type \"2\" if you wish to lose weight: ");
		int bulkorcut = keyboard.nextInt();
		System.out.println(bulkorcut);
		
		if (bulkorcut == 1)
		{
			System.out.println("To gain weight you must take in approximately " + bulk + " calories a day.");
		}
		
		else if (bulkorcut == 2)
		{
			System.out.println("To lose weight you must take in approximately " + cut + " calories a day.");
		}
		
		else
		{	
			System.out.println("You didn't type in 1 or 2. Restart program.");
		}	
	}
}

Basically I took all the formulas from THIS thread on bodybuilding.com.

Step by step this is how it works..

-Asks for the user's weight in pounds then automatically converts to kg.
-Asks for the user's bodyfat percentage.
-Asks for the user's activity level.
-Calculates user's LBM by using entered weight and bodyfat percentage.
-Uses Katch-McArdle forumla to calculate BMR.
-Multiplies BMR by activity level to aquire maintenance level.


Then the user can proceed from 2 choices..

-Calculating calorie intake to gain weight.
-Calculating calorie intake to lose weight.


These are calculated by either adding or subtracting 20% of the maintenance level calories.
Code:
		System.out.println("Type \"1\" if you wish to gain weight otherwise type \"2\" if you wish to lose weight: ");
			int bulkorcut = keyboard.nextInt();
	while (bulkorcut != 1 || bulkorcut != 2) {
		System.out.println("Invalid Entry! Type \"1\" if you wish to gain weight otherwise type \"2\" if you wish to lose weight: ");
			bulkorcut = keyboard.nextInt();
		}
		if (bulkorcut == 1)
		System.out.println("To gain weight you must take in approximately " + bulk + " calories a day.");
		
		else (bulkorcut == 2)
			System.out.println("To lose weight you must take in approximately " + cut + " calories a day.");
Shorter and doesn't require them to restart the program if they accidentally hit the wrong number.
Great job on the conversion equations and the sort.
__________________

Last edited by A Man(level-3) : 01-23-2012 at 05:45 AM.
Reply With Quote
Reply



Cheap RS Gold Store  Runescape Gold

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

All times are GMT +1. The time now is 09:09 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.6.1