-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathBodyMassIndex.java
More file actions
56 lines (42 loc) · 1.67 KB
/
Copy pathBodyMassIndex.java
File metadata and controls
56 lines (42 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import javax.swing.JOptionPane;
/**@author Lemuel M. Uhuru
* @Date June 6, 2013
* Book Title: From Control Structures through Objects by Tony Gaddis
* Page: 189 Problem 3: Body Mass Index
*
* @Description Write a program that calculates and displays
* a persons body mass index (BMI). A person BMI is calculated
* with the following formula BMI = Weight X 703 / Height^2
*/
public class BodyMassIndex {
public static void main(String[] args) {
// Declare variables to hold user weight and height
// Using data-type String to store String return value
// from JOptionPane
String input1, input2;
// Declare constant to store BMI
double BMI;
// Initialize variables to hold user input.
input1 = JOptionPane.showInputDialog(null, "Enter weight in pounds");
input2 = JOptionPane.showInputDialog(null, "Enter height in inches");
// Convert user input to double values
double weight = Double.parseDouble(input1);
double height = Double.parseDouble(input2);
// Initialize BMI variable
BMI = weight * (703 / (Math.pow(height, 2)));
// Design control structure to determine if user
// weight is optimal, under, or over.
if ( BMI >= 18.5 & BMI <= 25){
JOptionPane.showMessageDialog(null, "Your BMI indicates Optimal Weight." );
// Personal Note:
// && evaluates the left side of the operation, & evaluates both sides
// of the operation, if its true, continues and evaluates the right side.
}
else if (BMI < 18.5){
JOptionPane.showMessageDialog(null, "Your BMI indicates that you're underweight");
}
else if (BMI > 25){
JOptionPane.showMessageDialog(null, "Your BMI indicates that you're overweight.");
}
}
}