Source of BMINoErrorCheck.java


  1: //BMINoErrorCheck.java

  3: import java.util.Scanner;

  5: public class BMINoErrorCheck
  6: {
  7:     public static void main(String[] args)
  8:     {
  9:         Scanner scnr = new Scanner(System.in);
 10:         int weightVal; // User defined weight (lbs)
 11:         int heightVal; // User defined height (in)
 12:         float bmiCalc; // Resulting BMI
 13:         char quitCmd;  // Indicates quit/continue

 15:         quitCmd = 'a';

 17:         while (quitCmd != 'q')
 18:         {
 19:             // Get user data
 20:             System.out.print("Enter weight (in pounds): ");
 21:             weightVal = scnr.nextInt();

 23:             System.out.print("Enter height (in inches): ");
 24:             heightVal = scnr.nextInt();

 26:             // Calculate BMI value
 27:             bmiCalc = ((float) weightVal /
 28:                        (float)(heightVal * heightVal)) * 703.0f;

 30:             //Print user health info
 31:             // Source: http://www.cdc.gov/
 32:             System.out.println("BMI: " + bmiCalc);
 33:             System.out.println("(CDC: 18.6-24.9 normal)");

 35:             // Prompt user to continue/quit
 36:             System.out.print("\nEnter any key ('q' to quit): ");
 37:             quitCmd = scnr.next().charAt(0);
 38:         }
 39:     }
 40: }