Skip to content

Commit 2fa1b55

Browse files
bmi calculator updated
1 parent 4c9ae15 commit 2fa1b55

33 files changed

+275
-120
lines changed

All APK/BMI Calculator.apk

122 KB
Binary file not shown.

All APK/DU website webview.apk

5.67 MB
Binary file not shown.

BMICalculator/.idea/deploymentTargetDropDown.xml

+19
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

BMICalculator/.idea/vcs.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

BMICalculator/app/src/main/AndroidManifest.xml

+11
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,17 @@
2121
<category android:name="android.intent.category.LAUNCHER" />
2222
</intent-filter>
2323
</activity>
24+
<activity
25+
android:name=".ResultShow"
26+
android:exported="true">
27+
<intent-filter>
28+
<action android:name="android.intent.action.MAIN" />
29+
30+
/>
31+
</intent-filter>
32+
</activity>
33+
34+
2435
</application>
2536

2637
</manifest>
Loading

BMICalculator/app/src/main/java/com/example/bmicalculator/MainActivity.java

+23-12
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import androidx.appcompat.app.AppCompatActivity;
44

5+
import android.content.Intent;
56
import android.os.Bundle;
67
import android.view.View;
78
import android.widget.Button;
@@ -11,7 +12,7 @@
1112
public class MainActivity extends AppCompatActivity {
1213

1314
Button button;
14-
TextView textView, editTextText3, textView3, textView2;
15+
TextView textView, editTextText3;
1516
EditText editTextNumberSigned, editTextNumberDecimal, editTextNumberDecimal2;
1617

1718
@Override
@@ -22,26 +23,36 @@ protected void onCreate(Bundle savedInstanceState) {
2223
button = findViewById(R.id.button);
2324
textView = findViewById(R.id.textView);
2425
editTextText3 = findViewById(R.id.editTextText3);
25-
textView3 = findViewById(R.id.textView3);
26-
textView2 = findViewById(R.id.textView2);
26+
// textView3 = findViewById(R.id.textView3);
27+
// textView2 = findViewById(R.id.textView2);
2728
editTextNumberSigned = findViewById(R.id.editTextNumberSigned);
2829
editTextNumberDecimal = findViewById(R.id.editTextNumberDecimal);
2930
editTextNumberDecimal2 = findViewById(R.id.editTextNumberDecimal2);
3031

3132
button.setOnClickListener(new View.OnClickListener() {
3233
@Override
3334
public void onClick(View v) {
34-
String wt = editTextNumberSigned.getText().toString();
35-
String ht1 = editTextNumberDecimal.getText().toString();
36-
String ht2 = editTextNumberDecimal2.getText().toString();
3735

38-
int weight = Integer.parseInt(wt);
39-
int feet = Integer.parseInt(ht1);
40-
int inch = Integer.parseInt(ht2);
41-
double ht = feet * 0.3048 + inch * 0.0254;
42-
double bmi = weight / (ht * ht);
36+
try {
37+
String wt = editTextNumberSigned.getText().toString();
38+
String ht1 = editTextNumberDecimal.getText().toString();
39+
String ht2 = editTextNumberDecimal2.getText().toString();
4340

44-
textView2.setText(String.format("Your BMI is %.2f Kg/m^2", bmi));
41+
int weight = Integer.parseInt(wt);
42+
int feet = Integer.parseInt(ht1);
43+
int inch = Integer.parseInt(ht2);
44+
double ht = feet * 0.3048 + inch * 0.0254;
45+
double bmi = weight / (ht * ht);
46+
47+
Intent intent = new Intent(MainActivity.this, ResultShow.class);
48+
intent.putExtra("bmii",bmi);
49+
startActivity(intent);
50+
} catch (Exception e) {
51+
e.printStackTrace();
52+
}
53+
54+
55+
// textView2.setText(String.format("Your BMI is %.2f Kg/m^2", bmi));
4556
}
4657
});
4758
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.example.bmicalculator;
2+
3+
import androidx.appcompat.app.AppCompatActivity;
4+
5+
import android.os.Bundle;
6+
import android.widget.TextView;
7+
8+
public class ResultShow extends AppCompatActivity {
9+
TextView bmiVal, bmiRep, bmiTitle;
10+
11+
@Override
12+
protected void onCreate(Bundle savedInstanceState) {
13+
super.onCreate(savedInstanceState);
14+
setContentView(R.layout.activity_result_show);
15+
16+
bmiVal = findViewById(R.id.bmiVal);
17+
bmiRep = findViewById(R.id.bmiRep);
18+
bmiTitle = findViewById(R.id.bmiTitle);
19+
20+
21+
double bmi = getIntent().getDoubleExtra("bmii", 0);
22+
bmiVal.setText(String.format("Your BMI is %.2f Kg/m^2", bmi));
23+
24+
if (bmi < 18.5) {
25+
bmiTitle.setText(R.string.Underweight);
26+
bmiRep.setText(R.string.UnderweightR);
27+
} else if (bmi >= 18.5 && bmi <= 24.9) {
28+
bmiTitle.setText(R.string.Normal);
29+
bmiRep.setText(R.string.NormalR);
30+
} else if (bmi >= 25 && bmi <= 29.9) {
31+
bmiTitle.setText(R.string.Overweight);
32+
bmiRep.setText(R.string.OverweightR);
33+
} else if (bmi >= 30 && bmi <= 34.9) {
34+
bmiTitle.setText(R.string.Obesity1);
35+
bmiRep.setText(R.string.Obesity1R);
36+
} else if (bmi >= 35 && bmi <= 39.9) {
37+
bmiTitle.setText(R.string.Obesity2);
38+
bmiRep.setText(R.string.Obesity2R);
39+
} else {
40+
bmiTitle.setText(R.string.Obesity3);
41+
bmiRep.setText(R.string.Obesity3R);
42+
}
43+
44+
}
45+
46+
47+
}
8.53 KB
Loading

BMICalculator/app/src/main/res/layout/activity_main.xml

+75-98
Original file line numberDiff line numberDiff line change
@@ -6,112 +6,89 @@
66
android:layout_height="match_parent"
77
tools:context=".MainActivity">
88

9+
<LinearLayout
10+
android:layout_width="match_parent"
11+
android:layout_height="match_parent"
12+
android:orientation="vertical"
13+
android:layout_marginTop="50dp">
914

15+
<TextView
16+
android:id="@+id/textView"
17+
android:layout_width="match_parent"
18+
android:layout_height="wrap_content"
19+
android:layout_marginTop="50dp"
20+
android:layout_marginLeft="50dp"
21+
android:layout_marginRight="50dp"
22+
android:text="Enter your weight:"
23+
android:textSize="18sp"
24+
android:textStyle="bold" />
1025

11-
<TextView
12-
android:id="@+id/textView"
13-
android:layout_width="186dp"
14-
android:layout_height="34dp"
15-
android:text="Enter your weight (kg)"
16-
android:textSize="16sp"
17-
android:textStyle="bold"
18-
app:layout_constraintBottom_toBottomOf="parent"
19-
app:layout_constraintEnd_toEndOf="parent"
20-
app:layout_constraintHorizontal_bias="0.493"
21-
app:layout_constraintStart_toStartOf="parent"
22-
app:layout_constraintTop_toTopOf="parent"
23-
app:layout_constraintVertical_bias="0.09" />
26+
<EditText
27+
android:id="@+id/editTextNumberSigned"
28+
android:layout_width="match_parent"
29+
android:layout_height="wrap_content"
30+
android:layout_margin="50dp"
31+
android:hint="Kg"
32+
android:inputType="numberSigned" />
2433

25-
<EditText
26-
android:id="@+id/editTextNumberSigned"
27-
android:layout_width="wrap_content"
28-
android:layout_height="wrap_content"
29-
android:ems="10"
30-
android:inputType="numberSigned"
31-
app:layout_constraintBottom_toBottomOf="parent"
32-
app:layout_constraintEnd_toEndOf="parent"
33-
app:layout_constraintHorizontal_bias="0.497"
34-
app:layout_constraintStart_toStartOf="parent"
35-
app:layout_constraintTop_toBottomOf="@+id/textView"
36-
app:layout_constraintVertical_bias="0.032" />
34+
<TextView
35+
android:id="@+id/editTextText3"
36+
android:layout_width="match_parent"
37+
android:layout_height="wrap_content"
38+
android:layout_marginTop="50dp"
39+
android:layout_marginLeft="50dp"
40+
android:layout_marginRight="50dp"
41+
android:text="Enter your height:"
42+
android:textSize="18sp"
43+
android:textStyle="bold" />
3744

38-
<TextView
39-
android:id="@+id/editTextText3"
40-
android:layout_width="wrap_content"
41-
android:layout_height="wrap_content"
42-
android:ems="10"
43-
android:inputType="text"
44-
android:text="Enter your height (feet)"
45-
android:textSize="16sp"
46-
android:textStyle="bold"
47-
app:layout_constraintBottom_toBottomOf="parent"
48-
app:layout_constraintEnd_toEndOf="parent"
49-
app:layout_constraintHorizontal_bias="0.497"
50-
app:layout_constraintStart_toStartOf="parent"
51-
app:layout_constraintTop_toBottomOf="@+id/editTextNumberSigned"
52-
app:layout_constraintVertical_bias="0.081" />
45+
<LinearLayout
46+
android:layout_width="wrap_content"
47+
android:layout_height="wrap_content"
48+
android:orientation="horizontal"
49+
android:layout_margin="20dp">
5350

54-
<EditText
55-
android:id="@+id/editTextNumberDecimal"
56-
android:layout_width="wrap_content"
57-
android:layout_height="wrap_content"
58-
android:ems="10"
59-
android:inputType="numberDecimal"
60-
app:layout_constraintBottom_toBottomOf="parent"
61-
app:layout_constraintEnd_toEndOf="parent"
62-
app:layout_constraintHorizontal_bias="0.497"
63-
app:layout_constraintStart_toStartOf="parent"
64-
app:layout_constraintTop_toBottomOf="@+id/editTextText3"
65-
app:layout_constraintVertical_bias="0.034" />
51+
<EditText
52+
android:id="@+id/editTextNumberDecimal"
53+
android:layout_width="150dp"
54+
android:layout_height="50dp"
55+
android:layout_margin="20dp"
56+
android:hint="Feet"
57+
android:inputType="numberDecimal" />
58+
<EditText
59+
android:id="@+id/editTextNumberDecimal2"
60+
android:layout_width="150dp"
61+
android:layout_height="50dp"
62+
android:layout_margin="20dp"
63+
android:hint="Inch"
64+
android:inputType="numberDecimal" />
6665

67-
<TextView
68-
android:id="@+id/textView3"
69-
android:layout_width="199dp"
70-
android:layout_height="45dp"
71-
android:text="Enter your height (inch)"
72-
android:textSize="16sp"
73-
android:textStyle="bold"
74-
app:layout_constraintBottom_toBottomOf="parent"
75-
app:layout_constraintEnd_toEndOf="parent"
76-
app:layout_constraintStart_toStartOf="parent"
77-
app:layout_constraintTop_toBottomOf="@+id/editTextNumberDecimal"
78-
app:layout_constraintVertical_bias="0.103" />
7966

80-
<EditText
81-
android:id="@+id/editTextNumberDecimal2"
82-
android:layout_width="wrap_content"
83-
android:layout_height="wrap_content"
84-
android:ems="10"
85-
android:inputType="numberDecimal"
86-
app:layout_constraintBottom_toBottomOf="parent"
87-
app:layout_constraintEnd_toEndOf="parent"
88-
app:layout_constraintHorizontal_bias="0.497"
89-
app:layout_constraintStart_toStartOf="parent"
90-
app:layout_constraintTop_toBottomOf="@+id/textView3"
91-
app:layout_constraintVertical_bias="0.051" />
67+
</LinearLayout>
9268

93-
<Button
94-
android:id="@+id/button"
95-
android:layout_width="139dp"
96-
android:layout_height="61dp"
97-
android:text="Calculate"
98-
android:textSize="20sp"
99-
app:layout_constraintBottom_toBottomOf="parent"
100-
app:layout_constraintEnd_toEndOf="parent"
101-
app:layout_constraintStart_toStartOf="parent"
102-
app:layout_constraintTop_toBottomOf="@+id/editTextNumberDecimal2"
103-
app:layout_constraintVertical_bias="0.2" />
69+
<Button
70+
android:id="@+id/button"
71+
android:layout_width="wrap_content"
72+
android:layout_height="wrap_content"
73+
android:text="Calculate"
74+
android:layout_gravity="center"
75+
android:layout_margin="60dp"
76+
android:textSize="20sp"
77+
/>
10478

105-
<TextView
106-
android:id="@+id/textView2"
107-
android:layout_width="243dp"
108-
android:layout_height="116dp"
109-
android:textAlignment="center"
110-
android:textSize="20sp"
111-
android:textStyle="bold"
112-
app:layout_constraintBottom_toBottomOf="parent"
113-
app:layout_constraintEnd_toEndOf="parent"
114-
app:layout_constraintStart_toStartOf="parent"
115-
app:layout_constraintTop_toBottomOf="@+id/button" />
79+
</LinearLayout>
80+
81+
82+
<!-- <TextView-->
83+
<!-- android:id="@+id/textView2"-->
84+
<!-- android:layout_width="243dp"-->
85+
<!-- android:layout_height="116dp"-->
86+
<!-- android:textAlignment="center"-->
87+
<!-- android:textSize="20sp"-->
88+
<!-- android:textStyle="bold"-->
89+
<!-- app:layout_constraintBottom_toBottomOf="parent"-->
90+
<!-- app:layout_constraintEnd_toEndOf="parent"-->
91+
<!-- app:layout_constraintStart_toStartOf="parent"-->
92+
<!-- app:layout_constraintTop_toBottomOf="@+id/button" />-->
11693

11794
</androidx.constraintlayout.widget.ConstraintLayout>

0 commit comments

Comments
 (0)