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 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...
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...
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....
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 “*”.
Java Program Use for loop 1.) Write a program to display the multiplication table of a...
Java Program Use for loop 1.) Write a program to display the multiplication table of a given integer. Multiplier and number of terms (multiplicand) must be user's input. Sample output: Enter the Multiplier: 5 Enter the number of terms: 3 5x0=0 5x1=5 5x2=10 5x3=15 2 Create a program that will allow the user to input an integer and display the sum of squares from 1 to n. Example, the sum of squares for 10 is as follows: (do not use...
Write a program that will calculate and display the cost of a gasoline purchase based on...
Write a program that will calculate and display the cost of a gasoline purchase based on the brand of gasoline, the octane rating and the amount purchased. Your program should first display a menu prompting the user for the brand of gasoline.  Next prompt the user for the amount of gasoline in liters. Finally, your program should calculate and display the cost of the gasoline purchase using the formula below. Cost of Discount Gasoline = ($2.49 - (100 - Octane Rating)...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT