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

public class Calculator_1_7 extends AppCompatActivity {
    EditText firstgauge;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_calculator_1_7);
        firstgauge = findViewById(R.id.rack_gauge1);
        firstgauge.requestFocus();

    }


    public void Rackmm_calculation(View v){
        EditText density = findViewById(R.id.rack_density1);
        EditText texture= findViewById(R.id.rack_texture1);
        EditText denier= findViewById(R.id.rack_denier1);
        TextView rack_mm=findViewById(R.id.rack_mm);

        try{
            float rack_gauge = Float.parseFloat(firstgauge.getText().toString());
            float rack_density = Float.parseFloat(density.getText().toString());
            float rack_texture = Float.parseFloat(texture.getText().toString());
            float rack_denier=Float.parseFloat(denier.getText().toString());

            double cal_gauge= 25.4/rack_gauge;
            double cal_gauge2= cal_gauge*cal_gauge;

            double cal_density=rack_density*2;
            double cal_density2=cal_density*cal_density;

            double cal_texture=rack_texture*rack_texture;

            double cal_denier= 0.01114*Math.sqrt(rack_denier);
            double cal_denier2=cal_denier*cal_denier;

            double course= Math.sqrt((cal_density2+(cal_texture*cal_gauge2)))+2.05*Math.sqrt((cal_density2+(cal_texture*cal_denier2)))+(7.28*cal_denier);
            double cal_rackmm=course*480;

            double cal_rackmm2=Math.round(cal_rackmm);

            rack_mm.setText(cal_rackmm2+"R/mm");
        }catch (NumberFormatException e){
            Toast.makeText(this.getApplicationContext(),"값을 제대로 입력해 주세요", Toast.LENGTH_LONG).show();
        }

    }

    public void Rackmm_calculation2(View v){
        EditText gauge = findViewById(R.id.rack_gauge2);
        EditText density = findViewById(R.id.rack_density2);
        EditText texture= findViewById(R.id.rack_texture2);
        EditText denier= findViewById(R.id.rack_denier2);
        TextView rack_mm=findViewById(R.id.rack_mm2);

        try{
            float rack_gauge = Float.parseFloat(gauge.getText().toString());
            float rack_density = Float.parseFloat(density.getText().toString());
            float rack_texture = Float.parseFloat(texture.getText().toString());
            float rack_denier=Float.parseFloat(denier.getText().toString());

            double cal_gauge= 25.4/rack_gauge;
            double cal_gauge2= cal_gauge*cal_gauge;

            double cal_density=10/rack_density;
            double cal_density2=cal_density*cal_density;

            double cal_texture=rack_texture*rack_texture;

            double cal_denier= 0.01371*Math.sqrt(rack_denier);
            double cal_denier2=cal_denier*cal_denier;

            double course= Math.sqrt((cal_density2+(cal_texture*cal_gauge2)))+2.05*Math.sqrt((cal_density2+(cal_texture*cal_denier2)))+(7.28*cal_denier);
            double cal_rackmm=course*480;

            double cal_rackmm2=Math.round(cal_rackmm);

            rack_mm.setText(cal_rackmm2+"R/mm");
        }catch (NumberFormatException e){
            Toast.makeText(this.getApplicationContext(),"값을 제대로 입력해 주세요", Toast.LENGTH_LONG).show();
        }

    }

    public void Rackmm_calculation3(View v){
        EditText gauge = findViewById(R.id.rack_gauge3);
        EditText density = findViewById(R.id.rack_density3);
        EditText texture= findViewById(R.id.rack_texture3);
        EditText denier= findViewById(R.id.rack_denier3);
        TextView rack_mm=findViewById(R.id.rack_mm3);

        try{
            float rack_gauge = Float.parseFloat(gauge.getText().toString());
            float rack_density = Float.parseFloat(density.getText().toString());
            float rack_texture = Float.parseFloat(texture.getText().toString());
            float rack_denier=Float.parseFloat(denier.getText().toString());

            double cal_gauge= 25.4/rack_gauge;
            double cal_gauge2= cal_gauge*cal_gauge;

            double cal_density=10/rack_density;
            double cal_density2=cal_density*cal_density;

            double cal_texture=rack_texture*rack_texture;

            double cal_denier= 0.019*Math.sqrt((12*rack_denier)-3)/3;
            double cal_denier2=cal_denier*cal_denier;

            double course= Math.sqrt((cal_density2+(cal_texture*cal_gauge2)))+2.05*Math.sqrt((cal_density2+(cal_texture*cal_denier2)))+(7.28*cal_denier);
            double cal_rackmm=course*480;

            double cal_rackmm2=Math.round(cal_rackmm);

            rack_mm.setText(cal_rackmm2+"R/mm");
        }catch (NumberFormatException e){
            Toast.makeText(this.getApplicationContext(),"값을 제대로 입력해 주세요", Toast.LENGTH_LONG).show();
        }

    }

}
