---
# System prepended metadata

title: AN25 課題No.04-1
tags: [課題]

---

# AN25 課題No.04-1
###### tags: `課題`

```xml=
//activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center"
    >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/text1"
        />

    <EditText
        android:id="@+id/edit_height"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="30dp"
        android:inputType="numberDecimal"
        />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/text2"
        />

    <EditText
        android:id="@+id/edit_weight"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="30dp"
        android:inputType="numberDecimal"
        />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/text4"
        />

    <EditText
        android:id="@+id/edit_age"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="30dp"
        android:inputType="numberDecimal"
        />

    <Button
        android:id="@+id/button_calc"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/text3"
        android:onClick="buttonMethod"
        />

    <TableRow
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="right"
        />
</LinearLayout>
```

```java=
//Mainactivity.java
package nhs00650.hal.ac.mybmi;

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.content.Intent;
import android.view.View;
import android.widget.TextView;
import android.widget.EditText;



public class MainActivity extends AppCompatActivity {

    private EditText heightEditText;
    private EditText weightEditText;
    private EditText ageEditText;

    float heightint;
    float weightint;

    float bmiint;
    String bmistr;

    float waweight;
    float rweight;
    String rweightStr;

    int age;

    float kaupfloat;
    String kaupString;
    float roherefloat;
    String rohereStr;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        heightEditText = (EditText)findViewById(R.id.edit_height);
        weightEditText = (EditText)findViewById(R.id.edit_weight);
        ageEditText = (EditText)findViewById(R.id.edit_age);
    }

    public void buttonMethod(View btn_calc) {
        heightint = Float.parseFloat(heightEditText.getText().toString());
        weightint = Float.parseFloat(weightEditText.getText().toString());
        age = Integer.parseInt(ageEditText.getText().toString());
        if(age <= 5){
            kaupMethod();
            Intent result_act = new Intent(MainActivity.this, Result.class);
            result_act.putExtra("KAUP", kaupfloat);
            result_act.putExtra("AGE", age);
            startActivity(result_act);
        }else if(age <=15){
            rohereMethod();
            Intent result_act = new Intent(MainActivity.this, Result.class);
            result_act.putExtra("ROHERE", roherefloat);
            result_act.putExtra("AGE", age);
            startActivity(result_act);
        }else{
            bmiMethod();
            Intent result_act = new Intent(MainActivity.this, Result.class);
            result_act.putExtra("BMI", bmiint);
            result_act.putExtra("GOODWEIGHT", rweight);
            result_act.putExtra("AGE", age);
            startActivity(result_act);
        }
    }

    public void kaupMethod(){
        heightint = heightint / 100;
        float heightintdub = heightint * heightint;
        kaupfloat = weightint / heightintdub;
        kaupString = String.format("%.5f", kaupfloat);
    }

    public void rohereMethod(){
        heightint = heightint / 100;
        float heightinttri = heightint * heightint * heightint;
        roherefloat = weightint / heightinttri * 10;
        rohereStr = String.format("%.5f", roherefloat);
    }

    public void bmiMethod() {
        heightint = heightint / 100;
        float heightintdub = heightint * heightint;
        bmiint = weightint / heightintdub;
        bmistr = String.format("%.5f",bmiint);

        waweight = heightint * heightint * 22;
        rweight = waweight - weightint;
        rweightStr = String.format("%.5f",rweight);

    }
}
```

```xml=
//result.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center"
    >

    <TextView
        android:id="@+id/result_index"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="30dp"
        android:textSize="30sp"
        android:textColor="#0000ff"
        />

    <TextView
        android:id="@+id/result_value"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="30dp"
        android:textSize="30sp"
        android:textColor="#ff0000"
        />

    <TextView
        android:id="@+id/result_judge"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="30dp"
        android:textSize="30sp"
        android:textColor="#ff0000"
        />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="30dip"
        android:text="@string/good_msg"
        />

    <TextView
        android:id="@+id/good_weight"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="30dp"
        android:textSize="30sp"
        android:textColor="#ff0000"
        />

    <Button
        android:text="@string/btn_reset"
        android:id="@+id/button_reset"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:onClick="buttonMethod"
        />



    <TableRow
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="right"
        />
</LinearLayout>
```

```java=
//result.java
package nhs00650.hal.ac.mybmi;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.content.Intent;
import androidx.appcompat.app.AppCompatActivity;

import androidx.appcompat.app.AppCompatActivity;

import org.w3c.dom.Text;


public class Result extends AppCompatActivity {

    private TextView resultTextView;
    private TextView judgeTextView;
    private TextView goodTextView;
    private TextView indexTextView;

    float bmiint;
    String bmistr;

    float kaupfloat;
    String kaupStr;
    int age;

    float roherefloat;
    String rohereStr;

    float goodint;
    String goodStr;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.result);

        resultTextView = (TextView)findViewById(R.id.result_value);
        judgeTextView = (TextView)findViewById(R.id.result_judge);
        goodTextView = (TextView)findViewById(R.id.good_weight);
        indexTextView = (TextView)findViewById(R.id.result_index);

        Bundle extras = getIntent().getExtras();
        if(extras != null){
            age = extras.getInt("AGE");

            bmiint = extras.getFloat("BMI");
            goodint = extras.getFloat("GOODWEIGHT");

            kaupfloat = extras.getFloat("KAUP");

            roherefloat = extras.getFloat("ROHERE");

            if(age <= 5){
                kpMethod();
            }else if(age <= 15){
                rohMethod();
            }else{
                peroperoMethod();
            }
        }
    }

    public void kpMethod(){
        indexTextView.setText(R.string.result_msg2);

        if(age < 1){
            if (kaupfloat < 16){
                judgeTextView.setText(R.string.result_judge_0);
            }else if(kaupfloat < 18){
                judgeTextView.setText(R.string.result_judge_1);
            }else {
                judgeTextView.setText(R.string.result_judge_2);
            }
        }else if(age < 2){
            if (kaupfloat < 15.5){
                judgeTextView.setText(R.string.result_judge_0);
            }else if(kaupfloat < 17.5){
                judgeTextView.setText(R.string.result_judge_1);
            }else {
                judgeTextView.setText(R.string.result_judge_2);
            }
        }else if(age < 3){
            if (kaupfloat < 15){
                judgeTextView.setText(R.string.result_judge_0);
            }else if(kaupfloat < 17){
                judgeTextView.setText(R.string.result_judge_1);
            }else {
                judgeTextView.setText(R.string.result_judge_2);
            }
        }else{
            if (kaupfloat < 14.5){
                judgeTextView.setText(R.string.result_judge_0);
            }else if(kaupfloat < 16.5){
                judgeTextView.setText(R.string.result_judge_1);
            }else {
                judgeTextView.setText(R.string.result_judge_2);
            }
        }

        kaupStr = String.format("%.5f",kaupfloat);
        resultTextView.setText(kaupStr);

    }

    public void rohMethod(){
        indexTextView.setText(R.string.result_msg3);

        if (roherefloat < 115){
            judgeTextView.setText(R.string.result_judge_0);
        }else if(roherefloat < 145){
            judgeTextView.setText(R.string.result_judge_1);
        }else {
            judgeTextView.setText(R.string.result_judge_2);
        }

        rohereStr = String.format("%.5f",roherefloat);
        resultTextView.setText(rohereStr);
    }

    public void peroperoMethod() {
        indexTextView.setText(R.string.result_msg);

        if(bmiint < 18.5){
            judgeTextView.setText(R.string.result_judge_0);
        }else if(bmiint < 25.0) {
            judgeTextView.setText(R.string.result_judge_1);
        }else{
            judgeTextView.setText(R.string.result_judge_2);
        }

        bmistr = String.format("%.5f",bmiint);
        resultTextView.setText(bmistr);

        goodStr = String.format("%.5f",goodint);
        goodTextView.setText(goodStr);

    }

    public void buttonMethod(View btn_reset){
        Intent reset_act = new Intent(Result.this, MainActivity.class);
        startActivity(reset_act);
    }
}
```

```xml=
//strings.xml
<resources>
    <string name="app_name">MyBMI</string>
    <string name="sub_name">Result</string>
    <string name="action_settings">MyBMI</string>
    <string name="text1">身長を入力してください(cm)</string>
    <string name="text2">体重を入力してください(kg)</string>
    <string name="text3">BMI値を計算</string>
    <string name="text4">年齢を入力してください</string>
    <string name="result_judge_0">やせています</string>
    <string name="result_judge_1">標準です</string>
    <string name="result_judge_2">太っています</string>
    <string name="result_msg">あなたの指標はBMI指標。BMI値は...</string>
    <string name="result_msg2">あなたの指標はKaup指標。Kaup値は...</string>
    <string name="result_msg3">あなたの指標はRohere指標。Rohere値は...</string>
    <string name="good_msg">標準体重まで</string>
    <string name="btn_reset">リセット</string>
</resources>
```

AndroidManifest.xmlは変更なし


## 雑談 (0→やまぴ 1→みや 2→やすい 3→りょうくん 4→アミカ 5→やの)












---
<span style="color: #ff3333">aaa</span>
<span style="text-decoration: underline">aaa</span>