package com.example.calcutator.Calculator2;

import android.os.Bundle;

import com.example.calcutator.R;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.snackbar.Snackbar;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;

import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class Calculator_2_9 extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_calculator_2_9);
    }
    public void turn_calculation(View v){
        /* 처리할 값이 있는 곳의 키의 값을 가져옴 */
        EditText inners = findViewById(R.id.inner_1);
        EditText outers = findViewById(R.id.outer_1);
        EditText turnss = findViewById(R.id.turns);
        EditText inners1 = findViewById(R.id.inner_2);
        EditText outers1 = findViewById(R.id.outer_2);
        TextView beamdata = findViewById(R.id.beamData);
        TextView beamturn = findViewById(R.id.beamTurn);

        try{
            float inner = Float.parseFloat(inners.getText().toString());
            float outer = Float.parseFloat(outers.getText().toString());
            float turns = Float.parseFloat(turnss.getText().toString());
            float inner1 = Float.parseFloat(inners1.getText().toString());
            float outer1 = Float.parseFloat(outers1.getText().toString());

            /* 계산 */
            double calcul1 = (float)(outer1-inner1)*turns/(outer-inner);
            double calcul2 = (float)(outer1+inner1)/2*calcul1/1000;

            /* 반올림 */
            double calculround1 = Math.round(calcul1);
            double calculround2 = Math.round(calcul2);

            /* 소수점을 지우기 위한 형변환 */
            int calculch = (int)calculround1;
            int calculch2 = (int)calculround2;
            beamturn.setText(calculch+"wag");
            beamdata.setText(calculch2+"meter");
        }catch (NumberFormatException e){
            Toast.makeText(this.getApplicationContext(),"값을 제대로 입력해 주세요", Toast.LENGTH_LONG).show();
        }



    }


}
