Hi,
This is my first blog post about my first android application. Its a Body Mass Index (BMI) calculator. It took me about 3 hours to design and complete this application. Given below are a couple of screen shots and a method to calculate BMI.
Code for BMI:
public void calculate()
{
try
{
float bmi,height,weight;
height=new Float(text1.getText().toString());
weight=new Float(text2.getText().toString());
bmi=weight/(height*height);
tv1.setText("BMI: " + Float.toString(bmi));
if (bmi<18.5)
{
tv2.setText("Result: Underweight");
tv2.setTextColor(Color.RED);
}
else if(bmi>18.5 && bmi<24.9)
{
tv2.setText("Result: Healthy");
tv2.setTextColor(Color.GREEN);
}
else if(bmi>25 && bmi<29.9)
{
tv2.setText("Result: Overweight");
tv2.setTextColor(Color.MAGENTA);
}
else if(bmi>30 && bmi<34.9)
{
tv2.setText("Result: Obese");
tv2.setTextColor(Color.MAGENTA);
}
else if(bmi>35 && bmi<39.9)
{
tv2.setText("Result: Severely Obese");
tv2.setTextColor(Color.MAGENTA);
}
else
{
tv2.setText("Result: Morbidly Obese");
tv2.setTextColor(Color.MAGENTA);
}
}
catch(Exception e)
{
finish();
//Toast.makeText(Calculator.this, "Exception: "+e, Toast.LENGTH_LONG);
}
}
can you make that height input to be taken in cms or ft,inches then it would be much easy otherwise every time we need to convert our height into mts and then we can calculate our bmi
ReplyDeleteThanks for asking...
ReplyDeleteThis is just the basic method for calculating BMI. The more advanced type for converting the values given will be added later on with the use of options menu and preferences.
Good one yar........
ReplyDeleteNow-a-days technology is moving in a fastest rate.This is one of the good application.This is one of the good quality post.
ReplyDeleteAndroid app developers