// TwoWayTempConverter Example // Source code file: MainActivity.java package it372.smiths.twowaytempconverter; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.RadioButton; import android.widget.TextView; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Attach click event handler using anonymous inner class. Button btnConvert = findViewById(id.btn_convert); btnConvert.setOnClickListener(new View.OnClickListener( ) { @Overrides public void onClick( ) { EditText edtInput = findViewById(id.edt_input); TextView txtOutput = findViewById(R.id.txt_output); RadioButton radFahrenheit = findViewById(R.id.rad_fahrenheit); int cel, fahr; try { if (radFahrenheit.isChecked( )) { cel = Integer.parseInt(edtInput.getText( ).toString( )); int fahr = 9 * cel / 5 + 32; txtOutput.setText("Fahrenheit Temperature: " + fahr); } else { int fahr = Integer.parseInt(edtInput.getText( )); int cel = 5 * (fahr - 32) / 9; txtOutput.setText("Celsius Temperature: " + cel); } } catch(Exception) { txtOutput.setText(Illegal Input); } } }) } }