Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.33 KB | None | 0 0
  1.  
  2. import android.support.v7.app.AlertDialog;
  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. import android.widget.Toast;
  9.  
  10.  
  11. public class MainActivity extends AppCompatActivity {
  12.  
  13.     @Override
  14.     protected void onCreate(Bundle savedInstanceState) {
  15.         super.onCreate(savedInstanceState);
  16.         setContentView(R.layout.activity_main);
  17.     }
  18.  
  19.     public void calcular(View view) {
  20.  
  21.         EditText tdolar = (EditText) findViewById(R.id.dolar);
  22.         String sdolar = tdolar.getEditableText().toString();
  23.         double ddolar = Double.parseDouble(sdolar);
  24.  
  25.         EditText treal = (EditText) findViewById(R.id.real);
  26.         String sreal  = treal.getEditableText().toString();
  27.         double dreal = Double.parseDouble(sreal);
  28.  
  29.     double resultado = dreal/ddolar;
  30.     TextView tresult = (TextView) findViewById(R.id.resultado);
  31.     tresult.setText("$ " +String.format("%.2f",resultado));
  32.  
  33.     Toast.makeText(this,"$ " +String.format("%.2f",resultado),
  34.             Toast.LENGTH_LONG).show();
  35.  
  36.         AlertDialog.Builder alerta = new AlertDialog.Builder(this);
  37.         alerta.setTitle("Resultado");
  38.         alerta.setMessage("$ " +String.format("%.2f",resultado));
  39.         alerta.show();
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement