Robert_JR

Temperature Converesion

Apr 18th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.01 KB | None | 0 0
  1. //Rijoanul Hasan Shanto
  2. //Thursday, April 19, 2018
  3.  
  4. package com.example.robert_jr.temperatureconversion;
  5.  
  6. import android.support.v7.app.AppCompatActivity;
  7. import android.os.Bundle;
  8. import android.view.View;
  9. import android.widget.Button;
  10. import android.widget.EditText;
  11. import android.widget.RadioButton;
  12. import android.widget.TextView;
  13.  
  14. import org.w3c.dom.Text;
  15.  
  16. public class MainActivity extends AppCompatActivity {
  17.  
  18.     private EditText edtInput;
  19.  
  20.     private RadioButton rbtnFtoC;
  21.     private RadioButton rbtnCtoF;
  22.     private Button btnConvert;
  23.  
  24.     private TextView txtResult;
  25.     @Override
  26.     protected void onCreate(Bundle savedInstanceState) {
  27.         super.onCreate(savedInstanceState);
  28.         setContentView(R.layout.activity_main);
  29.  
  30.         edtInput = (EditText) findViewById(R.id.editInput);
  31.         rbtnCtoF = (RadioButton) findViewById(R.id.rbtnCtoF);
  32.         rbtnFtoC = (RadioButton) findViewById(R.id.rbtnFtoC);
  33.         btnConvert = (Button) findViewById(R.id.btnConvert);
  34.         txtResult = (TextView) findViewById(R.id.txtResult);
  35.  
  36.  
  37.         btnConvert.setOnClickListener(new View.OnClickListener() {
  38.             @Override
  39.             public void onClick(View v) {
  40.                 String Sedit = edtInput.getText().toString();
  41.  
  42.                 if(Sedit.length() > 0 && !Sedit.equals(""))
  43.                 {
  44.                     double in = Double.parseDouble(Sedit), temp = 0;
  45.  
  46.                     if(rbtnCtoF.isChecked())
  47.                     {
  48.                         temp = ((in * 9 ) / 5) + 32;
  49.  
  50.                         txtResult.setText(String.valueOf(temp));
  51.                     }
  52.                     else if(rbtnFtoC.isChecked())
  53.                     {
  54.                         temp = ((in - 32) / 9) * 5;
  55.  
  56.                         txtResult.setText(String.valueOf(temp));
  57.                     }
  58.                     else txtResult.setText("Select Option!");
  59.                 }
  60.  
  61.                 else txtResult.setText("No Input Detected!");
  62.             }
  63.         });
  64.     }
  65. }
Add Comment
Please, Sign In to add comment