Skip to content

Commit

Permalink
feat: add calcular peso ideal
Browse files Browse the repository at this point in the history
  • Loading branch information
Rodrigo-Sarmento committed Mar 23, 2023
1 parent 6cd9d69 commit 024b79f
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 4 deletions.
17 changes: 17 additions & 0 deletions .idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions app/src/main/java/com/digo/calculadorimc/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.TextView;
import android.widget.Toast;

Expand All @@ -16,8 +17,11 @@ public class MainActivity extends AppCompatActivity {
private EditText etAltura;
private TextView teResultado;
private TextView teSituacao;
private TextView tePesoIdeal;
private Button btCalcular;
private Button btLimpar;
private RadioButton rbMasculino;
private RadioButton rbFeminino;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -28,8 +32,11 @@ protected void onCreate(Bundle savedInstanceState) {
etAltura = findViewById(R.id.etAltura);
teResultado = findViewById(R.id.teResultado);
teSituacao = findViewById(R.id.teSituacao);
tePesoIdeal = findViewById(R.id.tePesoIdeal);
btCalcular = findViewById(R.id.btCalcular);
btLimpar = findViewById(R.id.btLimpar);
rbMasculino = findViewById(R.id.rbMasculino);
rbFeminino = findViewById(R.id.rbFeminino);

btCalcular.setOnClickListener(new View.OnClickListener() {
@Override
Expand Down Expand Up @@ -59,10 +66,21 @@ private void btCalcularOnClick(){
etAltura.requestFocus();
return;
}

double peso = Double.parseDouble(etPeso.getText().toString());
double altura = Double.parseDouble(etAltura.getText().toString());
double imc = peso / Math.pow(altura,2);
teResultado.setText(new DecimalFormat("0.00").format(imc));
double pesoIdeal = 0;

if(rbMasculino.isChecked()){
pesoIdeal = 22 * (altura * altura);
tePesoIdeal.setText("Seu peso ideal é "+new DecimalFormat("0.00").format(pesoIdeal)+"kg");
}else if(rbFeminino.isChecked()){
pesoIdeal = 21 * (altura * altura);
tePesoIdeal.setText("Seu peso ideal é "+new DecimalFormat("0.00").format(pesoIdeal)+"kg");
}

if(imc >= 18.5 && imc <= 24.9){
teSituacao.setText("Parabéns-você está em seu peso normal!");
}else if(imc > 24.9 && imc <= 29.9){
Expand All @@ -83,5 +101,6 @@ private void btLimparOnClick(){
etAltura.setText("");
teResultado.setText("IMC");
teSituacao.setText("Situação");
tePesoIdeal.setText("Peso Ideal");
}
}
36 changes: 33 additions & 3 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@color/white"
>


Expand All @@ -16,7 +17,7 @@
android:textStyle="bold"
android:textColor="@color/black"
android:textColorHint="@color/black"
android:hint="Peso em kg"
android:hint="Peso em kg (ex:75.7)"
android:maxLength="8"
android:textSize="40dp"/>

Expand All @@ -29,9 +30,26 @@
android:textStyle="bold"
android:textColorHint="@color/black"
android:maxLength="7"
android:hint="Altura em m²"
android:hint="Altura em m (ex:1.75)"
android:textSize="40dp"/>

<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/rbMasculino"
android:text="MASCULINO"
android:checked="true"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/rbFeminino"
android:text="FEMININO"/>
</RadioGroup>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand All @@ -50,6 +68,16 @@
android:textColor="@color/black"
android:text="Situação"
android:textSize="20dp"
/>

<TextView
android:id="@+id/tePesoIdeal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textColor="#0674CC"
android:text="Peso Ideal"
android:textSize="30dp"
android:paddingBottom="50dp"/>

<LinearLayout
Expand All @@ -64,8 +92,9 @@
android:layout_height="wrap_content"
android:background="#AAEE97"
android:onClick="btCalcularOnclick"
android:text="CALCULAR"
android:text="Calcular"
android:textSize="20dp"
android:padding="10dp"
android:layout_marginHorizontal="10dp"/>

<Button
Expand All @@ -76,6 +105,7 @@
android:textSize="20dp"
android:onClick="btLimparOnclick"
android:background="#EA7995"
android:padding="10dp"
android:layout_marginHorizontal="10dp"/>
</LinearLayout>
</LinearLayout>
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<resources>
<string name="app_name">CalculadorIMC</string>
<string name="app_name">Calculador de IMC/Peso Ideal</string>
</resources>

0 comments on commit 024b79f

Please sign in to comment.