Question

In: Computer Science

Java - Write a program to calculate a user’s BMI and display his/her weight status. The...

Java - Write a program to calculate a user’s BMI and display his/her weight status. The status is defined as Underweight, Normal, Overweight and obese if BMI is less than 18.5, 25, 30 or otherwise respectively. You need to read weight (in kilogram) and height (in metre) from the user as inputs. The BMI is defined as the ratio of the weight and the square of the height. [10 marks]

Solutions

Expert Solution

Java code:

import java.util.Scanner;
public class Main{
   public static void main(String[] args){
   Scanner input=new Scanner(System.in);
   //initializing weight and height
   float weight,height;
   //asking for weight
   System.out.print("Enter weight: ");
   //accepting it
   weight=input.nextFloat();
   //asking for height
   System.out.print("Enter height: ");
   //accepting it
   height=input.nextFloat();
   //finding bmi
   float bmi=weight/(height*height);
   //checking if it is less than 18.5
   if(bmi<18.5f)
   //printing Underweight
   System.out.println("Underweight");
   //checking if it is less than 25.0
   else if(bmi<25.0f)
   //printing Normal
   System.out.println("Normal");
   //checking if it is less than 30.0
   else if(bmi<30.0f)
   //printing Overweight
   System.out.println("Overweight");
   else
   //printing Obese
   System.out.println("Obese");
   }
}


Screenshot:


Input and Output:


Related Solutions

Write a program that accepts user’s section, and display them back with the format “*** Section:...
Write a program that accepts user’s section, and display them back with the format “*** Section: user’s section ***”.
Create a BMI calculator that reads the user’s weight and height (providing an option for the...
Create a BMI calculator that reads the user’s weight and height (providing an option for the user to select which formula to use), and then calculates and displays the user’s body mass index. Also, display the BMI categories and their values from the National Heart Lung and Blood Institute: http://www.nhlbi.nih.gov/health/educational/lose_wt/BMI/bmicalc.htm (Links to an external site.) so the user can evaluate his/her BMI. Java Version
Write a program in java that uses methods to input data for calculation, calculate, and display...
Write a program in java that uses methods to input data for calculation, calculate, and display the results of the calculations. That is, there are at least three methods. The problem is to write a program that calculates the area of a rectangle. This action should be repeatable.
Write a program that accepts user’s name, password and address and display them back using the...
Write a program that accepts user’s name, password and address and display them back using the format “Hi, I am user’s name. I live at user’s address.”. Restrictions: ▪ Use only three variables. ▪ Make sure you support spaces.
USING MATLAB: Create a BMI calculator application that reads the user’s weight in pounds and height...
USING MATLAB: Create a BMI calculator application that reads the user’s weight in pounds and height in inches (or, if you prefer, the user’s weight in kilograms and height in meters), then calculates and displays the user’s body mass index. Also, the application should display the following information from the Department of Health and Human Services/National Institutes of Health so the user can evaluate his/her BMI: BMI VALUES ("Underweight : Less than 18.5 Normal : between 18.5 and 24.9 Overweight...
Assess Mr. Glenn Birch height and weight. Calculate his BMI and % usual body weight. What...
Assess Mr. Glenn Birch height and weight. Calculate his BMI and % usual body weight. What would be a reasonable weight goal for Mr. Glenn Birch? Give your rationale for the method you used to determine the goals. This is a middle-aged male, who presented recently to the Bariatric Center for evaluation and treatment of longstanding morbid obesity and associated comorbidities. He underwent standard bariatric evaluation, consults, diagnostics, and preoperative Medifast induced weight loss in anticipation of elective bariatric surgery....
Create a Java application called ValidatePassword to validate a user’s password. Write a program that asks...
Create a Java application called ValidatePassword to validate a user’s password. Write a program that asks for a password, then asks again to confirm it. If the passwords don’t match or the rules are not fulfilled, prompt again. Your program should include a method that checks whether a password is valid. From that method, call a different method to validate the uppercase, lowercase, and digit requirements for a valid password. Your program should contain at least four methods in addition...
Write a Java program that will ask the user for his/her salary (numerical integer salary) and...
Write a Java program that will ask the user for his/her salary (numerical integer salary) and then convert this numerical salary into income class. The following is a guideline to the income class used. The numeric range within parenthesis maps to the preceding class. If the user gave you a number greater than 700,000 or less than 10,000, you should print a message that the input is invalid. In this code, DO NOT USE && OPERATOR. You should use if-else....
Write a Java program that will ask the user for his/her mark (numerical integer mark) and...
Write a Java program that will ask the user for his/her mark (numerical integer mark) and then convert this numerical mark into letter grades. The following is a guideline to the grading scale used. The numeric range within parenthesis maps to the preceding letter grade. If the user gave you a number greater than 100 or less than 0, you should print a message that the input is invalid. In this code, DO NOT USE && OPERATOR. You should use...
Write a java program that read a line of input as a sentence and display: ...
Write a java program that read a line of input as a sentence and display:  Only the uppercase letters in the sentence.  The sentence, with all lowercase vowels (i.e. “a”, “e”, “i”, “o”, and “u”) replaced by a strike symbol “*”.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT