Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.myapplication;
- import androidx.appcompat.app.AppCompatActivity;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.TextView;
- import android.widget.Toast;
- public class MainActivity extends AppCompatActivity {
- // 1
- EditText etHeight;
- EditText etWeight;
- Button btnCalculate;
- TextView tvBmi;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- // 2
- etHeight = findViewById(R.id.etHeight);
- etWeight=findViewById(R.id.etWeight);
- btnCalculate = findViewById(R.id.btnCalculate);
- tvBmi = findViewById(R.id.tvBmi);
- }
- public void calaculate(View view) {
- String stw = etWeight.getText().toString();
- if (stw.length()>0) {
- double weight = Double.parseDouble(stw);
- double height = Double.parseDouble(etHeight.getText().toString());
- double bmi = weight / Math.pow(height,2);
- tvBmi.setText(bmi+"");
- if (bmi>=20 && bmi<=24) {
- Toast.makeText(this,"Very good",Toast.LENGTH_LONG).show();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement