package com.example.gsmcalculator;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
private EditText inputEpi, inputPpi, inputEpiYarn, inputPpiYarn;
private TextView cottonGSMResult, cottonSpandexGSMResult, afterWashCottonGSMResult, afterWashCottonSpandexGSMResult;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
inputEpi = findViewById(R.id.input_epi);
inputPpi = findViewById(R.id.input_ppi);
inputEpiYarn = findViewById(R.id.input_epiYarn);
inputPpiYarn = findViewById(R.id.input_ppiYarn);
cottonGSMResult = findViewById(R.id.cottonGSMResult);
cottonSpandexGSMResult = findViewById(R.id.cottonSpandexGSMResult);
afterWashCottonGSMResult = findViewById(R.id.afterWashCottonGSMResult);
afterWashCottonSpandexGSMResult = findViewById(R.id.afterWashCottonSpandexGSMResult);
Button calculateButton = findViewById(R.id.calculateButton);
calculateButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
calculateGSM();
}
});
}
private void calculateGSM() {
try {
double epi = Double.parseDouble(inputEpi.getText().toString());
double ppi = Double.parseDouble(inputPpi.getText().toString());
double epiYarn = Double.parseDouble(inputEpiYarn.getText().toString());
double ppiYarn = Double.parseDouble(inputPpiYarn.getText().toString());
double calculationResult = (epi / epiYarn) + (ppi / ppiYarn);
double cottonGSM = calculationResult * 23.24;
double cottonSpandexGSM = cottonGSM * 1.10;
double afterWashCottonGSM = cottonGSM * 1.06;
double afterWashCottonSpandexGSM = cottonSpandexGSM * 1.14;
cottonGSMResult.setText("Cotton Fabrics GSM: " + String.format("%.2f", cottonGSM));
cottonSpandexGSMResult.setText("Cotton Spandex Fabrics GSM: " + String.format("%.2f", cottonSpandexGSM));
afterWashCottonGSMResult.setText("Cotton Fabrics After Wash GSM: " + String.format("%.2f", afterWashCottonGSM));
afterWashCottonSpandexGSMResult.setText("Cotton Spandex Fabrics GSM After Wash: " + String.format("%.2f", afterWashCottonSpandexGSM));
cottonGSMResult.setVisibility(View.VISIBLE);
cottonSpandexGSMResult.setVisibility(View.VISIBLE);
afterWashCottonGSMResult.setVisibility(View.VISIBLE);
afterWashCottonSpandexGSMResult.setVisibility(View.VISIBLE);
} catch (NumberFormatException e) {
Toast.makeText(this, "Please enter valid numeric values for all inputs.", Toast.LENGTH_SHORT).show();
}
}
}