0% encontró este documento útil (0 votos)
33 vistas12 páginas

Trabajo de Inv. Appcalculadora

Descargar como docx, pdf o txt
Descargar como docx, pdf o txt
Descargar como docx, pdf o txt
Está en la página 1/ 12

“AÑO DEL DIALOGO Y LA RECONCILIACION

NACIONAL”
UNIVERSIDAD PRIVADA TELESUP
INGENIERIA DE SISTEMAS

ASIGNATURA: DESARROLLO DE APLICACIONES

TEMA: APK.CALCULADORA

PROFESOR: JORGE SANTIAGO


NOLASCO VALENZUELA

FECHA: 27 DE ENERO DEL 2018

ALUMNO: SALCEDO BLAS, JHONATAN


VIDAL ZEVALLOS, YOEL FREDDY
MACHACA, RAUL

LIMA – PERU
2019
APPCalculadora

Package inkadroid.com.calculadora;
import android. app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget. Button;
import android.widget. ImageView;
import android.widget.TextView;
public class MainActivity extends Activity implements View
OnClickListener {
private TextView txtResultado;
private Button btn0, btn1 ,btn2, btn3 ,btn4, bt.n5, btn6, btn7
,btn8,btn9,btnPunto;
private Button btnSuma,btnResta,btnDivision,
btnMultiplicacion, btnPotenciacion, btnRaiz ;
private Button btnlqual,btnBorrar,btnlimpiar;
private ImageView ImgBorrar;
private String VaIorA=" ";
private String ValorB=" ";
private char operador:' ';
private String cont=" " ;
private boolean decimal = false;
private Button dato;
boolean hayPunto=false;
private double a;
@Override
protected void onCreate (Bundle savedlnstancestate) {
super. onCreate (savedlnstanceState) ;
setContentView (R. layout. activity main) ;

ImgBorrar=( ImageView) findviewById (R. id. ImgBorrar)


txtResultado: (TextView) findViewByld (R. id.
txtResultado);
btn0=(Button)findViewByTd(R.id.btn0);
btn1=(Button) findViewByld (R. id.btn1) ;
btn2=(Button) f.indViewByld (R.id.btn2) ;
btn3=( Button ) findViewByld ( R. id. btn3 ) ;
btn4=(Button) findViewByld (R. id. btn4 ) ;
btn5=( Button ) findViewByld ( R. id . btn5 ) ;
btn6=(Button) findViewByld (R. id. btn6) ;
btn7=(Button) findViewByld (R. id.btn7) ;
btn8=(Button) findViewByld (R. id. btn8 ) ;
btn9=( Button ) findViewByld ( R. id . btn9 ) ;

btnRaiz=(Button) findViewByld (R. id.btnRaiz) ;


btnlgual=(Button) findViewByld ( R. id. btnlgual ) ;
btnBorrar=(Button) findViewByld (R. id. btnBorrar) ;
btnPunto=(Button) findViewByld (R. id. btnPunto) ;
btnlimpiar=(Button) findViewByld (R. id.btnlimpiar) ;
Btn0. setOnClickListener (this) ;
btn1. setOnClickListener (this) ;
btn2. setOnClickListener (this) ;
btn3. setOnClickListener (this) ;
btn4. setOnClickListener (this) ;
btn5. setOnClickListener (this) ;
btn6. setOnClickListener (this) ;
btn7. setOnClickListener (this) ;
btn8. setOnClickListener (this) ;
btn9. setOnClickListener (this) ;
btnSuma. setOnClickListener ( this ) ;
btnResta. setOnClickListener (this ) ;
btnDivision. setOnClickListener (this) ;
btnMultiplicacion . setOnClickListener ( this ) ;
btnPotenciacion. setOnClickListener (this) ;
btnRaiz . setOnClickListener (this) ;
btnlgual . setOnClickListener (this) ;
btnBorrar. setOnClickListener ( this) ;
btnPunto . setOnClickListener ( this ) ;
btnLimpiar. setOnClickListener (this) ;

@Override

public void onClick(View v) {


switch (v. getId ( ) )
{

btnSuma=(Button) findViewByld (R. id.btnSuma) ;


btnResta=(Button) findViewByld (R. id. btnResta) ;
btnDivision=(Button) findViewByld (R. id. btnDivision)
btnMultiplicacion= (Button) findViewByld (R. id.
btnMultiplicacion);
btnPotenciacion: (Button) findViewByld (R. id.
btnPotenciacion ) ;

case R. id.btn0:
case R. id.btn1:
case R. id.btn2:
case R. id.btn3:
case R- id.btn4:
case R. id.btn5:
case R. id.btn6:
case R. id.btn7:
case R. id.btn8:
case R. id.btn9:
dato= (Button)v;
ValorA+=dato. getText ( ) ;
txtResultado. setText (ValorA) ;
break;

case R. id. btnSuma:


case R. id. btnResta:
case R. id. btnDivision:
case R. id. btnMultiplicacion:
case R. id. btnPotenciacion:
case R.id.btnRaiz:
Button dato= (Button) v;
operador=dato. getText ( ) . charAt (0) ;
ValorB=VaIorA;
Valora=" ";
txtResultado. setText ( " " ) ;
break;

case R. id.btnLimpiar:
case R. id.btnBorrar:
ValorA = " " ;
ValorB = " ";
txtResultado. setText ( " " ) ;
break;

case R. id. btnlgual :


double resultado=0.0;
double a;
double b;
if (operador=='+')
{

resultado = Float.parseFloat(VaIorB)
+ Float. parseFloat (VaIorA) ;
)

else if (operador==
r-r
)
{

resultado : Eloat.parseFloat (ValorB)


- Float. parseEloat (VaIorA) ;
)

eLse if (operador-:r / r
¡
{

resultado FIoat.parseFloat(ValorB)
/ f'Ioat. parseFloat (ValorA) ;
)

eJ.se if (operador::t * t
)
{

resultado EIoat . parseFloat (Val-orB * Eloat.parseFloat (VaIorA) ;


)

resultado) );
)

eLse if (oPerador::r ^ r
)
{

a Float.parseEloat (ValorB) ;
b : E1oat. parseFloat (VaIorA) ;
resultado : Math.pob/ (a, b) ;
)

txtResultado. setText (String. valueOf (

ValorA:re sultado+'r rr'


\/¡ I n rP:rf fr .
I

break;
case R. id.btnPunto:

dato : (Button) v;
try
{

a Float. parseFloat (ValorA) ;


if (a%1::0) {
ValorA+:dato. getText ( ) ;
txtResultado. setText (ValorA) ;
)

else if (a?1!:0) {
hayPunto:true;
return;
i
)
catch (NumberFormatException nfe )
{

return;
]
break;
)
)
)
]

package colocaelnombredetudominio . com. calculadora;


import android. app.Activity;
import android.os.Bundle;
import android.view.View;
import android. widget . Button,'
import android.widget. ImageView;
import android.widget.TextView;
pubJ.ic class MainActivity extends Activity implements View
. OnClickListener {
private TextView txtResultado;
private Button btn0,btn1,btn2,btn3,btn4,btn5,btn6,btn7
, btnB, btn9, btnPunto;
private Button btnSuma,btnResta,btnDivision,
btnMultipllcacion, btnPotenciacion, btnRai z ;
private Button btnlgual,btnBorrar,btnlimpiar;
private ImageView ImgBorrar;
private St ring VaIorA:" " ,'

private String ValorB:" ";


private char operador:' ';
private String cont-'r r' '
private boolean decimal : false;
private Button dato;
boolean hayPunto:fa1se;
private double a;
GOverride
protected void onCreate (Bundle savedlnst.anceState) {
super. onCreate (savedlnstanceState) ;
setContentView (R. layout. activity main) ;
ImgBorrar: (ImaqeView) fíndviewByld (R. id. ImgBorrár)
txtResultado: (TextView) findViewByld (R. id.
txtResultado);
btnO:(Button) findViewByld(R.id.btnO);
btnl: (Button) findViewByld (R. id. btnl) ;
btn2: (Button) f indViewByld (R. id.btn2) ;
btn3: (Button) findViewByld (R. id. btn3) ;
btn4: (Button) findViewByld (R. id. btn4 ) ;
bln5:(Button)findViewByTd(R.id.btn5);
btn6: (Button) findViewByld (R. id.btn6) ;
btn7: ( Button ) findViewByld ( R. id. btn7 ) ;
btn8: (Button) findViewByld (R. id. btn8 ) ;
btn9: (Button) findViewByld (R. id.btn9) ;
GOverride
B0 public void onClick(View v) {
svritch (v. getTd O )
{

btnSuma: (Button) findViewByld (R. id. btnSuma) ;


btnResta: (Button) findViewByld (R. id. btnResta) ;
btnDivision: (Button) findViewByld (R. id. btnDivision)
btnMultiplicacion: (Button) findViewByld (R. id.
t¡tnMultiplicacion) ;
btnPotenciacion: (Button) findViewByld (R. id.
btnPotenciacion);
btnRaiz: ( Button) findViewByld (R. id. btnRaiz ) ;
b,tnlgual: (Button) findViewByld (R. id.btnlgual) ;
btnBorra¡: (Button) findViewByld (R. id. btnBorrar) ;
btnPunto: ( Button ) findViewByld ( R. id . btnPunto ) ;
btnlimpiar: (Button) findViewByld (R. íd. btnlimpiar) ;
btnO. setOnClickI.istener (this) ;
btn1. setOnClicklistener (this) ;
bLn2. setOnClickT-istener (this) ;
btn3. setOnClick]-istener (this) ;
btn4. setOnClick]-istener (this) ;
btn5. setOnClick]-istener (this) ;
btn6. setOnClick]-istener (this) ;
btn7. setOnClick]-istener (thís) ;
btnB. setOnClickT-istener (this) ;
btn9. setOnClicklistener (this) ;
btnSuma. setOnClickl-istener (this ) ;
btnResta. setOnClick]-istener (this) ;
btnDivision. setOnClickl-istener (this) ;
btnMult iplicacion . setOnClickI,i stener ( this ) ;
btnPotenciacion. setOnClickl-istener (this) ;
btnRaiz . setOnClickl-istener (this ) ;
btnlgual . setOnClickl-istener (this) ;
btnBorrar. setOnClick],istener ( this) ;
btnPunto . setOnClickListener (this) ;
btnlimpiar. setOnClicklistener (this) ;

case R. id. btn0


case R. id.btnl
case R. id.bLn2
case R. id.btn3
case R. id.btn4
case R. id. btn5
case R. id.btn6
case R. id.btn7
case R. id.btnB
case R. id.btn9
dato (Button) v;
ValorA+:dato. getText ( ) ;
txtResultado. setText (VaIorA) ;
break;
case R. id.btnSuma:
case R. id. btnResta:
case R. id. btnDivision:
casé R. id. btnMultiplicacion:
case R. id. btnPotenciacion:
case R. id. btnRaiz :
Button dato: (Button) v;
operador:dato. qetText ( ) . charAt (0) ;
ValorB:VaIorA;
VaIorA:tttI ;
txtResultado. setText ( " " ) i
break;
case R. id.btnlimpiar:
case R. id. btnBorrar:
ValorA : rr Ir '
\\

txtResultado. setText (rr rr ) '


break;
case R. id. btnlgual:
double resurtado:0. 0;
double a;
double b;
if (operador::'+' )
{

resultado EIoat.parseEloat(ValorB)
+ Float. parseFloat (VaIorA) ;
)

else if (operador::r-r )
{

resultado Float.parseEloat (ValorB)


- Eloat. parseFloat (ValorA) ;
)

eJ-se if (operador::t / t
¡
{

resultado Eloat.parseFloat (VaIorB)


/ Float.parseFloat (ValorA) ;
i
e1se if (operador:: | * I
) {

resultado Float.parseEloat (ValorB)


* Eloat . parseEloat (VaIorA) ;
)

else if (operador::r ^ r
)
{

a Eloat.parseFloat (ValorB);
b Float. parseFloat (ValorA) ;
resultado: Math.poh/(a,b);
)

txtResultado. setText (String. valueOf (

resultado) );
ValorA:resultado+rr rr '
ValorB:w rr '
break;
7
case R. id.btnPunto:
dato (Button) v;
try
{

a Float.parseEloat (ValorA);
if (a%1::0) {
ValorAt:dato. getText ( ) ;
txtResultado. setText (ValorA) ; 1sB )

else if (a?;1!:0) {
hayPunto:true;
return;
)
)
catch (NumberEormatException fe)
{

return;
)

También podría gustarte