Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. package br.com.ifro.estudos;
  2.  
  3. import android.support.v7.app.AppCompatActivity;
  4. import android.os.Bundle;
  5. import android.view.View;
  6. import android.widget.EditText;
  7. import android.widget.TextView;
  8.  
  9. public class MainActivity extends AppCompatActivity {
  10.  
  11. EditText edCatetoA, edCatetoB;
  12. TextView tvResultado;
  13.  
  14. int catetoA, catetoB;
  15. double resultado;
  16.  
  17. @Override
  18. protected void onCreate(Bundle savedInstanceState) {
  19. super.onCreate(savedInstanceState);
  20. setContentView(R.layout.activity_main);
  21.  
  22. // vinculação de elementos da view com o controlador
  23. edCatetoA = (EditText) findViewById(R.id.edCatetoA);
  24. edCatetoB = (EditText) findViewById(R.id.edCatetoB);
  25. tvResultado = (TextView) findViewById(R.id.tvResultado);
  26. }
  27.  
  28. public void onCalcular(View v) {
  29. // c² = a² + b²
  30. catetoA = Integer.parseInt(edCatetoA.getText().toString());
  31. catetoB = Integer.parseInt(edCatetoB.getText().toString());
  32.  
  33. resultado = Math.sqrt(Math.pow(catetoA, 2) + Math.pow(catetoB, 2));
  34.  
  35. tvResultado.setText("O valor da hipotenusa é: " + resultado);
  36. }
  37.  
  38. public void onLimpar(View v) {
  39. edCatetoA.setText("");
  40. edCatetoB.setText("");
  41. tvResultado.setText("");
  42. }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement