Created
September 9, 2013 02:33
-
-
Save justinmusgrove/6490840 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static String bmiDescription (double bmi) { | |
if (bmi < 18.5) { | |
return "You are underweight."; | |
} else { | |
if (bmi > 25) { | |
return "You are overweight."; | |
} else { | |
return "Your weight is optimal."; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static double calculateBMI (double height, double weight) { | |
return weight * 703 / (height * height); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Variables | |
double weight; // The user's weight | |
double height; // The user's height | |
double bmi; // The user's BMI |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Calculate the user's body mass index. | |
bmi = calculateBMI(height, weight); | |
// Display the user's BMI. | |
System.out.println("Your body mass index (BMI) is " + bmi); | |
System.out.println(bmiDescription(bmi)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create a Scanner object for keyboard input. | |
Scanner keyboard = new Scanner(System.in); | |
// Tell the user what the program will do. | |
System.out.println("This program will calculate your body mass index, or BMI."); | |
// Get the user's weight. | |
System.out.print("Enter your weight, in pounds: "); | |
weight = keyboard.nextDouble(); | |
// Get the user's height. | |
System.out.print("Enter your height, in inches: "); | |
height = keyboard.nextDouble(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment