package com.example.calcutator.Calculator2;

import android.content.Intent;
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.Gravity;
import android.view.View;
import android.widget.EditText;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
import android.widget.Toast;

public class Calculator_2_1 extends AppCompatActivity {
    TableLayout table;
    Integer calcul = 0;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_calculator_2_1);
        table = findViewById(R.id.table1);
        Intent intent = getIntent();
        int bar = intent.getExtras().getInt("bars");
        calcul = Integer.valueOf(bar);
        for(int i=1; i<=bar; i++){
            TableRow row = new TableRow(this);
            TextView barnum = new TextView(this);
            EditText et1 = new EditText(this);
            EditText et2 = new EditText(this);
            TextView length = new TextView(this);
            barnum.setText("GB"+i);
            barnum.setGravity(Gravity.CENTER);
            et1.setId(100+i);
            et1.setGravity(Gravity.CENTER);
            et2.setId(200+i);
            et2.setGravity(Gravity.CENTER);
            length.setId(300+i);
            length.setText("00m/y");
            length.setGravity(Gravity.CENTER);
            row.addView(barnum);
            row.addView(et1);
            row.addView(et2);
            row.addView(length);
            table.addView(row,i);
        }
    }
    public void calcul(View v){
        float sums1= 0;
        try{
            for(int i=1; i<=calcul; i++){
                EditText mils = findViewById(100+i);
                EditText rackmms = findViewById(200+i);
                TextView length = findViewById(300+i);
                Float mil = Float.parseFloat(mils.getText().toString());
                Float rackmm = Float.parseFloat(rackmms.getText().toString());
                double calcul1 = mil*91.44/480*rackmm/1000;
                double calculround1 = Math.round(calcul1*10)/10.0;
                length.setText(calculround1+"m/y");
            }
        }catch (NumberFormatException e){
            Toast.makeText(this.getApplicationContext(),"값을 제대로 입력해 주세요", Toast.LENGTH_LONG).show();
        }

    }


}
