Practicing for an intro to java class so I decided to make my own diet calculator. First the code then i'll explain..
// KMJT's Diet Calculator
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();
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.");
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.