binibiningtinamoran

MyBMI

Oct 11th, 2019
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.20 KB | None | 0 0
  1. import javax.swing.JOptionPane;
  2.  
  3. public class BMI {
  4.  
  5.     public static void main(String[] args) {
  6.        
  7.         //Getting input
  8.         String response = JOptionPane.showInputDialog(null,
  9.                 "Enter your height in inches");
  10.         double height = Double.parseDouble(response);
  11.         response = JOptionPane.showInputDialog(null,
  12.                 "Enter your weight in pounds");
  13.         double weight = Double.parseDouble(response);
  14.  
  15.         //Calculation
  16.  
  17.         double bodyIndex;
  18.         bodyIndex = (weight * 703) / (height * height);
  19.  
  20.         //Conditionals
  21.         String result;
  22.         if (bodyIndex < 16) {
  23.             result = "Invalid";
  24.         } else if (bodyIndex >= 16 && bodyIndex < 18.5) {
  25.             result = "underweight";
  26.         } else if (bodyIndex >= 18.5 && bodyIndex < 25) {
  27.             result = "Healthy";
  28.         } else {
  29.             result = "Overweight";
  30.         }
  31.         JOptionPane.showMessageDialog(null,
  32.                 String.format("Height: %,.2f in\n" +
  33.                         "Weight: %,.2f lbs\n" +
  34.                         "BMI: %,.2f\n" +
  35.                         "Classification: %s\n", height, weight, bodyIndex, result));
  36.         }
  37.  
  38. }
Advertisement
Add Comment
Please, Sign In to add comment