Diet Calculator

Discussion in 'Programming General' started by kmjt, Jan 21, 2012.

Diet Calculator
  1. Unread #1 - Jan 21, 2012 at 6:02 AM
  2. kmjt
    Joined:
    Aug 21, 2009
    Posts:
    14,450
    Referrals:
    8
    Sythe Gold:
    449

    kmjt -.- The nocturnal life chose me -.-
    Banned

    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.
     
  3. Unread #2 - Jan 21, 2012 at 6:57 PM
  4. The Black Tux
    Joined:
    Apr 19, 2009
    Posts:
    10,306
    Referrals:
    30
    Sythe Gold:
    55
    Vouch Thread:
    Click Here
    Two Factor Authentication User Cool Kid Former OMM Cook RsProd Sythe Awards 2012 Winner Village Drunk

    The Black Tux Veteran
    The Black Tux Donor Java Programmers PHP Programmers

    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 :)
     
  5. Unread #3 - Jan 23, 2012 at 12:45 AM
  6. A Man(level-3)
    Joined:
    Jun 28, 2010
    Posts:
    288
    Referrals:
    0
    Sythe Gold:
    3

    A Man(level-3) Forum Addict

    Diet Calculator

    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. ^_^
     
< RS Grand Exchange info Grabber [Source] | vb.net label problem >

Users viewing this thread
1 guest


 
 
Adblock breaks this site