Welcome to the Blog !! Today we will learn to build our own BMI (Body Mass Index) calculator which will help us to decide our BMI Category (Underweight , Normal Weight , Overweight , Obesity).
✅ Problem Statement :
Build a BMI calculator which will take height and weight of a person as an input and displays calculated BMI and BMI Category as an Output.
🔴 BMI Categories :
- Underweight - If BMI <=18.5
- Normal Weight - If BMI is in between 18.6 - 24.9
- Overweight - If BMI is in between 25 - 29.9
- Obesity - If BMI is greater than 30
📑Let's Code :)
Note* : If you are not familiar with Eclipse IDE please check my previous posts. This post will not contain basics of Eclipse.
Step 1 : Follow this -
Open Eclipse → Open Project / Create Project (bmiCalculator) → Create Package (bmiCalculator) → Create 2 Java Classes , BmiCalculator.java and Main.java
- BmiCalculator.java will contain all the methods to calculate BMI and to decide BMI category.
- Main.java will contain main( ) method to test those functionalities.
Step 2 : Firstly, we will complete BmiCalculator.java -
This class contains -
- Getters and Setters
- Method to calculate BMI
- Method to decide BMI Category
Here is the sample code for BmiCalculator.java :
Step 3 : Now we will complete Main.java
This class contains -
- main ( ) method
- Objects of Scanner class and BmiCalculator class
- Take input from user
- Call respective methods to compute the results
- Display result on the Console using prinf( ) method and println( ) method of Output Stream
Here is the Sample Output -
Output 2 |
Yeahhh 🎉🥳 We are done with one more project 😄😄
Check Source Code of this Project Here
Hope you like this post 😉
You can reach us by entering your details in Contact Us box in the side panel💬
All the Best 👍👍👍👍
Happy Learning 😇😇😇