package com.example.calcutator.Calculator1;

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.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class Calculator_1_5 extends AppCompatActivity {
    EditText ht;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_calculator_1_5);
        ht = findViewById(R.id.sample_horizontal);
        ht.requestFocus();
    }
    public void sample_calculation(View v){
        String test = "가공지폭(inch)*2.54*91.44/(가로길이*세로길이)*시험편중량(g)";
        //계산을 위한 입력값 가져오기
        EditText paperin = findViewById(R.id.paper_inch);
        EditText vc = findViewById(R.id.sample_vertical);
        EditText examg = findViewById(R.id.sample_g);
        EditText weights = findViewById(R.id.sample_weight);
        EditText length = findViewById(R.id.sample_length);
        EditText papermil1 = findViewById(R.id.sample_mil_1);
        EditText wellnums = findViewById(R.id.sample_well);
        EditText gaygis = findViewById(R.id.sample_gauge);
        TextView papercalcul1 = findViewById(R.id.paper_weight_view);
        TextView papercalcul2 = findViewById(R.id.paper_weight2_view);
        TextView papermil2 = findViewById(R.id.sample_mil_2_view);
        TextView paperwidth = findViewById(R.id.paper_width_view);

        try{
            Float paperinch = Float.parseFloat(paperin.getText().toString());
            Float horizontal = Float.parseFloat(ht.getText().toString());
            Float vertical = Float.parseFloat(vc.getText().toString());
            Float semplekg = Float.parseFloat(examg.getText().toString());
            Float weight = Float.parseFloat(weights.getText().toString());
            Float lengths = Float.parseFloat(length.getText().toString());
            Float parpermil1s = Float.parseFloat(papermil1.getText().toString());
            Float wellnum = Float.parseFloat(wellnums.getText().toString());
            Float gaygi = Float.parseFloat(gaygis.getText().toString());
            //계산 시작
            //가공지 중량 계산
            double calcul1 = paperinch*2.54*91.44/(vertical*horizontal)*semplekg;
            Double calculround = Math.round(calcul1*10)/10.0;
            //생지 중량 계산
            double calcul2 = calcul1*((100-weight)/100);
            Double calculround2 = Math.round(calcul2*10)/10.0;
            //생지 밀도 계산
            double calcul3 = parpermil1s*((100-lengths)/100);
            Double calculround3 = Math.round(calcul3*10)/10.0;
            //생지 제직 폭 계산
            double calcul4 = wellnum*2.54*paperinch/gaygi;
            Double calculround4 = Math.round(calcul4*10)/10.0;
            papercalcul1.setText(calculround+"g");
            papercalcul2.setText(calculround2+"g");
            papermil2.setText(calculround3+"cm");
            paperwidth.setText(calculround4+"");
        }catch (NumberFormatException e){
            Toast.makeText(this.getApplicationContext(),"값을 제대로 입력해 주세요", Toast.LENGTH_LONG).show();
        }



    }


}
