• Log in or sign up for an account here: https://www.sythe.org/login

Diet Calculator

kmjt

-.- The nocturnal life chose me -.-

Banned
Joined
Aug 21, 2009
Sythe Gold
449
Messages
14,450
Location
Canada
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.
 
Two Factor Authentication User
Sythe Awards 2011 Winner
Cook
Cool Kid
Former OMM
RsProd
Sythe Awards 2012 Winner
Village Drunk
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 :)
 
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. ^_^
 
Runescape Gamblingrunescape gambling
Back
Top