Está en la página 1de 19

2º SMR PMDM

Entrega 2

Marcelo Cuasapud Tanicuchi

Índice
AppRadioButton............................................................................................................................... 3
Funcionamiento............................................................................................................................ 3
Ejemplo de sumar......................................................................................................................... 3
Ejemplo de resta........................................................................................................................... 4

PMDM Marcelo Cuasapud Tanicuchi


Página 1 de 19
2º SMR PMDM

Ejemplo de multiplicación.............................................................................................................. 4
Ejemplo de división y división por 0..............................................................................................5
Ejemplo de porcentaje.................................................................................................................. 5
Ejemplo de exponente.................................................................................................................. 6
Ejemplo de raíz............................................................................................................................. 6
Ejemplo de logaritmo.................................................................................................................... 7
AppCheckBox.................................................................................................................................. 7
Funcionamiento............................................................................................................................ 7
Ejemplo de las operaciones.......................................................................................................... 8
Ejemplo de división por cero......................................................................................................... 8
AppSpinner...................................................................................................................................... 9
Funcionamiento............................................................................................................................ 9
Ejemplo de suma.......................................................................................................................... 9
Ejemplo de resta......................................................................................................................... 10
Ejemplo de multiplicación............................................................................................................ 10
Ejemplo de división y división por cero.......................................................................................11
Ejemplo de porcentaje................................................................................................................11
Ejemplo de exponenciación........................................................................................................ 12
Ejemplo de raíz........................................................................................................................... 12
Ejemplo de logaritmo..................................................................................................................13
Anexo............................................................................................................................................. 14
Código AppRadioButton.............................................................................................................. 14
Código AppCheckBox................................................................................................................. 15
Código AppSpinner..................................................................................................................... 17

AppRadioButton
Funcionamiento

PMDM Marcelo Cuasapud Tanicuchi


Página 2 de 19
2º SMR PMDM

Esta aplicación es una calculadora que funciona a través de las clases Radioutton.
Estas clases permiten elegir una opción de entre otras opciones que se encuentran en el mismo
grupo de RadioButtons.
Para realizar cualquier operación escribimos un valor en las cajas que nos piden escribir un valor y
escogemos la operación deseada. Para ejecutar la operación pulsaremos el botón de calcular una
vez hechos los pasos anteriores y el resultado aparecerá en la parte superior.

Ejemplo de sumar

Ejemplo de resta

PMDM Marcelo Cuasapud Tanicuchi


Página 3 de 19
2º SMR PMDM

Ejemplo de multiplicación

PMDM Marcelo Cuasapud Tanicuchi


Página 4 de 19
2º SMR PMDM

Ejemplo de división y división por 0

Ejemplo de porcentaje

Ejemplo de exponente

PMDM Marcelo Cuasapud Tanicuchi


Página 5 de 19
2º SMR PMDM

Ejemplo de raíz

PMDM Marcelo Cuasapud Tanicuchi


Página 6 de 19
2º SMR PMDM

Ejemplo de logaritmo

AppCheckBox
Funcionamiento
Esta aplicación es una calculadora que funciona de forma similar a la anterior.
Esta vez hemos usado las clases check box que te permiten elegir varias opciones de todas las
opciones posibles.
Como en la aplicación anterior se escriben los valores en las cajas de texto que piden escribir un
valor y se escoge la operación u operaciones deseadas.
Una vez hecho esto se pulsa el botón calcular y se ejecutarán las operaciones que estén
marcadas.
El resultado final aparecerá al lado de cada operación correspondiente.

PMDM Marcelo Cuasapud Tanicuchi


Página 7 de 19
2º SMR PMDM

Ejemplo de las operaciones

Ejemplo de división por cero

PMDM Marcelo Cuasapud Tanicuchi


Página 8 de 19
2º SMR PMDM

AppSpinner
Funcionamiento
Esta calculadora es similar a las anteriores, sin embargo, esta vez hemos usado la clase spinner
que recoge todas las operaciones anteriores.
Se escriben valores en las cajas de texto en las que se pide un número y en la parte superior al
hacer clic en la operación, que por defecto es SUMA, se desplegarán las demás operaciones.
Una vez escogida la operación el resultado aparecerá encima del botón calcular.

Ejemplo de suma

PMDM Marcelo Cuasapud Tanicuchi


Página 9 de 19
2º SMR PMDM

Ejemplo de resta

Ejemplo de multiplicación

PMDM Marcelo Cuasapud Tanicuchi


Página 10 de 19
2º SMR PMDM

Ejemplo de división y división por cero

Ejemplo de porcentaje

PMDM Marcelo Cuasapud Tanicuchi


Página 11 de 19
2º SMR PMDM

Ejemplo de exponenciación

Ejemplo de raíz

PMDM Marcelo Cuasapud Tanicuchi


Página 12 de 19
2º SMR PMDM

Ejemplo de logaritmo

PMDM Marcelo Cuasapud Tanicuchi


Página 13 de 19
2º SMR PMDM

Anexo
Código AppRadioButton
package com.example.appradiobutton;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

private EditText num1, num2;


private TextView textresultado;
private RadioButton rsuma, rresta, rmultiplicar, rdivision, rporcentaje,
rexponienciacion, rraiz, rlogaritmo;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

num1 =(EditText) findViewById(R.id.num1);


num2 =(EditText) findViewById(R.id.num2);

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

PMDM Marcelo Cuasapud Tanicuchi


Página 14 de 19
2º SMR PMDM

rsuma =(RadioButton) findViewById(R.id.rsuma);


rresta=(RadioButton) findViewById(R.id.rresta);
rmultiplicar =(RadioButton) findViewById(R.id.rmultiplicar);
rdivision =(RadioButton) findViewById(R.id.rdividir);
rporcentaje =(RadioButton) findViewById(R.id.rporcentaje);
rexponienciacion =(RadioButton) findViewById(R.id.rexponente);
rraiz =(RadioButton) findViewById(R.id.rraiz);
rlogaritmo =(RadioButton) findViewById(R.id.rlogaritmo);

public void Calcular (View view){


String valor1_string = num1.getText().toString();
String valor2_string = num2.getText().toString();

double valor1_int = Integer.parseInt(valor1_string);


double valor2_int = Integer.parseInt(valor2_string);

if (rsuma.isChecked() == true ){
double suma = valor1_int + valor2_int;
String resultado = String.valueOf(suma);
textresultado.setText(resultado);
}else if (rresta.isChecked() == true ){
double resta = valor1_int - valor2_int;
String resultado = String.valueOf(resta);
textresultado.setText(resultado);
}else if (rmultiplicar.isChecked() == true ){
double multip = valor1_int * valor2_int;
String resultado = String.valueOf(multip);
textresultado.setText(resultado);
}else if (rdivision.isChecked() == true ){
double dividir = 0;
if(valor2_int != 0) {
dividir = valor1_int / valor2_int;
String resultado = String.valueOf(dividir);
textresultado.setText(String.valueOf(resultado));
} else if (valor2_int == 0) {
Toast.makeText(getApplicationContext(), "No se puede dividir por
0", Toast.LENGTH_LONG).show();
}
}else if (rporcentaje.isChecked() == true ){
double porcentaje = valor1_int * (valor2_int/100);
String resultado = String.valueOf(porcentaje);
textresultado.setText(resultado);
}else if (rexponienciacion.isChecked() == true ){
double exponente = Math.pow(valor1_int, valor2_int);
String resultado = String.valueOf(exponente);
textresultado.setText(resultado);
}else if (rraiz.isChecked() == true ){
double raiz = Math.pow(valor1_int, (1 / valor2_int));
String resultado = String.valueOf(raiz);
textresultado.setText(resultado);
}else if (rlogaritmo.isChecked() == true ){
double log = (Math.log(valor2_int) / Math.log(valor1_int));
String resultado = String.valueOf(log);
textresultado.setText(resultado);
}

PMDM Marcelo Cuasapud Tanicuchi


Página 15 de 19
2º SMR PMDM

}
}

Código AppCheckBox
package com.example.appcheckbox;

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {


private EditText num1, num2;
private TextView textsuma, textresta, textmult, textdiv, textexpo, textraiz,
textlog, textporcent;
private CheckBox suma, resta, multiplicar, dividir, porcentaje, exponente,
raiz, logaritmo;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
num1 =(EditText) findViewById(R.id.num1);
num2 =(EditText) findViewById(R.id.num2);

textsuma=(TextView) findViewById(R.id.rsuma);
textresta=(TextView) findViewById(R.id.rresta);
textmult=(TextView) findViewById(R.id.rmult);
textdiv=(TextView) findViewById(R.id.rdiv);
textporcent=(TextView) findViewById(R.id.rporcent);
textraiz=(TextView) findViewById(R.id.rraiz);
textlog=(TextView) findViewById(R.id.rlog);
textexpo=(TextView) findViewById(R.id.rexp);

suma =(CheckBox) findViewById(R.id.chsuma);


resta=(CheckBox) findViewById(R.id.chresta);
multiplicar =(CheckBox) findViewById(R.id.chmult);
dividir =(CheckBox) findViewById(R.id.chdiv);
porcentaje =(CheckBox) findViewById(R.id.chporcent);
exponente =(CheckBox) findViewById(R.id.chexp);
raiz =(CheckBox) findViewById(R.id.chraiz);
logaritmo =(CheckBox) findViewById(R.id.chlog);

public void Calcular (View view){


String valor1_string = num1.getText().toString();
String valor2_string = num2.getText().toString();

double valor1_int = Integer.parseInt(valor1_string);


double valor2_int = Integer.parseInt(valor2_string);

PMDM Marcelo Cuasapud Tanicuchi


Página 16 de 19
2º SMR PMDM

if (suma.isChecked() == true ){
double suma = valor1_int + valor2_int;
String resultado = String.valueOf(suma);
textsuma.setText(" = " +resultado);
}else {}
if (resta.isChecked() == true ){
double resta = valor1_int - valor2_int;
String resultado = String.valueOf(resta);
textresta.setText(" = " +resultado);
}else{}
if (multiplicar.isChecked() == true ){
double multip = valor1_int * valor2_int;
String resultado = String.valueOf(multip);
textmult.setText(" = "+resultado);
}else{}
if (dividir.isChecked() == true ){
double dividir = 0;
if(valor2_int != 0) {
dividir = valor1_int / valor2_int;
String resultado = String.valueOf(dividir);
textdiv.setText(String.valueOf(" = " +resultado));
} else if (valor2_int == 0) {
Toast.makeText(getApplicationContext(), "No se puede dividir por
0", Toast.LENGTH_LONG).show();
}
}else{}
if (porcentaje.isChecked() == true ){
double porcentaje = valor1_int * (valor2_int/100);
String resultado = String.valueOf(porcentaje);
textporcent.setText(" = " +resultado);
}else{}
if (exponente.isChecked() == true ){
double exponente = Math.pow(valor1_int, valor2_int);
String resultado = String.valueOf(exponente);
textexpo.setText(" = "+resultado);
}else{}
if (raiz.isChecked() == true ){
double raiz = Math.pow(valor1_int, (1 / valor2_int));
String resultado = String.valueOf(raiz);
textraiz.setText(" = "+resultado);
}else{}
if (logaritmo.isChecked() == true ){
double log = (Math.log(valor2_int) / Math.log(valor1_int));
String resultado = String.valueOf(log);
textlog.setText(" = " +resultado);
}else{}

}
public void Borrar (View view){
textsuma.setText("");
textresta.setText("");
textmult.setText("");
textdiv.setText("");
textporcent.setText("");
textexpo.setText("");
textraiz.setText("");
textlog.setText("");

}
}

PMDM Marcelo Cuasapud Tanicuchi


Página 17 de 19
2º SMR PMDM

Código AppSpinner
package com.example.appspinner;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

private EditText num1, num2;


private TextView tvres;
private Spinner spOperaciones;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
num1 =(EditText) findViewById(R.id.num1);
num2 =(EditText) findViewById(R.id.num2);

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

spOperaciones = (Spinner) findViewById(R.id.spinner);

String [] listaOperaciones = {"SUMAR", "RESTAR", "MULTIPLICAR",


"DIVIDIR", "PORCENTAJE", "EXPONENCIACIÓN", "RAÍZ", "LOGARITMO"};
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
R.layout.spinner_custom_text, listaOperaciones);
spOperaciones.setAdapter(adapter);

public void Calcular (View view){


String valor1_string = num1.getText().toString();
String valor2_string = num2.getText().toString();

double valor1_int = Integer.parseInt(valor1_string);


double valor2_int = Integer.parseInt(valor2_string);

String seleccionado = spOperaciones.getSelectedItem().toString();

if (seleccionado.equals("SUMAR") ){
double suma = valor1_int + valor2_int;
String resultado = String.valueOf(suma);

PMDM Marcelo Cuasapud Tanicuchi


Página 18 de 19
2º SMR PMDM

tvres.setText(String.valueOf(resultado));
}else {}
if (seleccionado.equals("RESTAR" )){
double resta = valor1_int - valor2_int;
String resultado = String.valueOf(resta);
tvres.setText(String.valueOf(resultado));
}else{}
if (seleccionado.equals("MULTIPLICAR" )){
double multip = valor1_int * valor2_int;
String resultado = String.valueOf(multip);
tvres.setText(String.valueOf(resultado));
}else{}
if (seleccionado.equals("DIVIDIR" )){
double dividir = 0;
if(valor2_int != 0) {
dividir = valor1_int / valor2_int;
String resultado = String.valueOf(dividir);
tvres.setText(String.valueOf(resultado));
} else if (valor2_int == 0) {
Toast.makeText(getApplicationContext(), "No se puede dividir por
0", Toast.LENGTH_LONG).show();
}

}else{}
if (seleccionado.equals("PORCENTAJE" )){
double porcentaje = valor1_int * (valor2_int/100);
String resultado = String.valueOf(porcentaje);
tvres.setText(String.valueOf(resultado));
}else{}
if (seleccionado.equals("EXPONENCIACIÓN" )){
double exponente = Math.pow(valor1_int, valor2_int);
String resultado = String.valueOf(exponente);
tvres.setText(String.valueOf(resultado));
}else{}
if (seleccionado.equals("RAÍZ" )){
double raiz = Math.pow(valor1_int, (1 / valor2_int));
String resultado = String.valueOf(raiz);
tvres.setText(String.valueOf(resultado));
}else{}
if (seleccionado.equals("LOGARITMO" )){
double log = (Math.log(valor2_int) / Math.log(valor1_int));
String resultado = String.valueOf(log);
tvres.setText(String.valueOf(resultado));
}else{}

}
public void Borrar (View view){
num1.setText("");
num2.setText("");
tvres.setText("0");

PMDM Marcelo Cuasapud Tanicuchi


Página 19 de 19

También podría gustarte