viernes, 3 de mayo de 2013

Código: src/com.androidcalculadora.calculadora/MainActivity.java



Código: Aplicación Calculadora

Nota: Los dos códigos se los voy a mandar a Denisse por correo.  Problema con el anterior. 

 

 

src/com.androidcalculadora.calculadora/MainActivity.java

 

package com.androidcalculadora.calculadora;

 

import android.app.Activity;

import android.os.Bundle;

import android.widget.*;

import android.view.*;

 

public class MainActivity extends Activity {

           

                        // Instancias de objetos a usar

                        private double valor_a, valor_b;

                        private EditText op_a, op_b;

                        private TextView resultado;

                       

                        // @Override

                       

                   public void onCreate(Bundle savedInstanceState) {

                  super.onCreate(savedInstanceState);

                  setContentView(R.layout.activity_main);

                   

                    // Asignamos los objetos

                    this.op_a = (EditText) findViewById(R.id.op_a);

                    this.op_b = (EditText) findViewById(R.id.op_b);

                    this.resultado = (TextView) findViewById(R.id.resultado);             

                }      

 

                                                          

                        public void cSumar(View view) {

if(this.op_a.getText().toString().length() > 0 && this.op_b.getText().toString().length() > 0) {

                       this.valor_a = Double.parseDouble(this.op_a.getText().toString());

                        this.valor_b = Double.parseDouble(this.op_b.getText().toString());   

                        this.resultado.setText(Double.toString((this.valor_a + this.valor_b)));                  

                        }

                }

 

                public void cRestar(View view) {

if(this.op_a.getText().toString().length() > 0 && this.op_b.getText().toString().length() > 0) {

                        this.valor_a = Double.parseDouble(this.op_a.getText().toString());

                        this.valor_b = Double.parseDouble(this.op_b.getText().toString());   

                        this.resultado.setText(Double.toString((this.valor_a - this.valor_b)));                   

                        }

                }

               

                public void cMultiplicar(View view) {

if(this.op_a.getText().toString().length() > 0 && this.op_b.getText().toString().length() > 0) {

                        this.valor_a = Double.parseDouble(this.op_a.getText().toString());

                        this.valor_b = Double.parseDouble(this.op_b.getText().toString());   

                        this.resultado.setText(Double.toString((this.valor_a * this.valor_b)));                   

                        }

                }

                 public void cDividir(View view) {

if(this.op_a.getText().toString().length() > 0 && this.op_b.getText().toString().length() > 0) {

                        this.valor_a = Double.parseDouble(this.op_a.getText().toString());

                        this.valor_b = Double.parseDouble(this.op_b.getText().toString());   

                        if(this.valor_b != 0) {

                                    this.resultado.setText(Double.toString((this.valor_a / this.valor_b)));                                

                        }

                        else {

                                    this.resultado.setText("Infinito");                        

                        }

                        }

                }      

            }

 

No hay comentarios:

Publicar un comentario