Está en la página 1de 15

UNIVERSIDAD DE CARTAGENA CENTRO TUTORIAL LORICA.

FACULTAD DE INGENIERÍA

PROGRAMA EDUCATIVO
INGENIERÍA DE SOFTWARE

ACTIVIDAD DE APRENDIZAJE UNIDAD 2

DESARROLLO DE APP

INSTRUCTOR:

MARTIN INDABURO

ESTUDIANTES:

JEINER LUIS MANGONES ANAYA

GERVIS ANTONIO PAJARO PAJARO

FIDEL ANTONIO HERNANDEZ ALTAMIRANDA

VI SEMESTRE

PERIODO 2019-2

LORICA-CORDOBA
1. DESARROLLAR UNA APPS EN ANDROID QUE CALCULE EL CUBO DE UN NUMERO, SI EL
NÚMERO ES MAYOR DE 100, LA APLICACIÓN MOSTRAR UN MENSAJE CON TOAST “ERES MUY
AFORTUNADO”

Código XML

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".CuboNumero">

<TextView
android:layout_width="match_parent"
android:layout_height="35dp"
android:text="Ingrese el numero"
android:textSize="20sp"/>

<EditText
android:id="@+id/et1"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginBottom="20dp"
android:inputType="number"
android:hint="Numero"/>

<Button
android:id="@+id/button"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="30sp"
android:onClick="calcular"
android:text="Calcular" />

<TextView
android:id="@+id/tv1"
android:layout_width="match_parent"
android:layout_height="50dp"
android:text="RESULTADO"
android:textSize="25sp"
android:gravity="center"/>

</LinearLayout>

CODIGO JAVA
package com.example.actividad;

import androidx.appcompat.app.AppCompatActivity;

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

public class CuboNumero extends AppCompatActivity {


private EditText et1;
private TextView tv1;

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

et1=(EditText)findViewById(R.id.et1);
tv1=(TextView)findViewById(R.id.tv1);
String cadena="";
Toast notificacion=Toast.makeText(this, cadena,Toast.LENGTH_SHORT);
notificacion.show();
}

public void calcular(View view){


String valor1=et1.getText().toString();
int num= Integer.parseInt(valor1);
int cubo=num*num*num;
String resul=String.valueOf(cubo);
tv1.setText(resul);

if(cubo>100){
//Toast.makeText(context: this, text:"Eres muy afortunado",
Toast.LENGTH_SHORT).show();
Toast notificacion=Toast.makeText(this,"Eres muy afortunado",Toast.LENGTH_SHORT);
notificacion.show();
}
}
}

2. DESARROLLAR UNA APLICACIÓN EN ANDROID QUE SIMULE LA TIRADA DE DOS DADOS.

ESTA APLICACIÓN TIENE DOS ELEMENTOS:

Una etiqueta llamada textViewResultado

y un botón llamado BotonDados


ESTA ES LA CLASE PRINCIPAL DE LA APLICACIÓN SE CREA DOS CAMPOS:

Uno de tipo TextView llamado etiqueta resultado Y otro de tipo Button llamado Boton Luego en el
método onCreate se crean las referencias de la interfaz gráfica con los campos que se crearon
anteriormente donde se mostrara el resultado de cuando se pulsa el botón

Se crea el método Lanzar

El cual tiene dos variables de tipo entero llamadas n1,n2 en las cuales se almacenara el resultado del
método ramdom que lo que hace es generar un numero aleatorio de 1 a 6 Y luego se muestran los dos
resultados en la etiquetaResultado.

package com.example.dados;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

TextView etiquetaResultado;

Button Boton;

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

etiquetaResultado=findViewById(R.id.textViewResultado);

Boton=findViewById(R.id.BotonDados);

public void Lanzar(View v){

int dado1=(int)(Math.random()*6)+1;

int dado2=(int)(Math.random()*6)+1;

etiquetaResultado.setText(dado1+":"+dado2);

}
}

3. DESARROLLAR UNA APPS EN ANDROID QUE DIGITADO 5 COMPRAS, REALICE LOS SIGUIENTES
CÁLCULOS:
 El total de la compra
 El IVA de la compra
 Si la compra es superior a 100.000 realizar un descuento del 10%
 Calcule cual es la compra más alta
 Utilizar ScrollView Vertical, para desplazar verticalmente la pantalla

ACTIVITI-MAIN.XML

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/tv1"
android:layout_width="match_parent"
android:layout_height="35dp"
android:gravity="center"
android:text="CALCULAR COMPRAS" />

<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:src="@drawable/compra" />

<EditText
android:id="@+id/et1"
android:layout_width="match_parent"
android:layout_height="40dp"
android:inputType="number"
android:hint="Ingrese el valor de la compra 1"/>

<EditText
android:id="@+id/et2"
android:layout_width="match_parent"
android:layout_height="40dp"
android:inputType="number"
android:hint="Ingrese el valor de la compra 2"/>

<EditText
android:id="@+id/et3"
android:layout_width="match_parent"
android:layout_height="40dp"
android:inputType="number"
android:hint="Ingrese el valor de la compra 3"/>

<EditText
android:id="@+id/et4"
android:layout_width="match_parent"
android:layout_height="40dp"
android:inputType="number"
android:hint="Ingrese el valor de la compra 4"/>

<EditText
android:id="@+id/et5"
android:layout_width="match_parent"
android:layout_height="40dp"
android:inputType="number"
android:hint="Ingrese el valor de la compra 5"/>

<Button
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginBottom="40dp"
android:onClick="calcular"
android:text="CALCULAR"/>

<TextView
android:id="@+id/tv2"
android:layout_width="match_parent"
android:layout_height="40dp"
android:gravity="left"
android:textColor="#FB8C00"
android:textSize="20dp" />

<TextView
android:id="@+id/tv3"
android:layout_width="match_parent"
android:layout_height="40dp"
android:gravity="left"
android:textColor="#FB8C00"
android:textSize="20dp"/>

<TextView
android:id="@+id/tv4"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginBottom="20dp"
android:gravity="left"
android:textColor="#FB8C00"
android:textSize="20dp"/>

<TextView
android:id="@+id/tv5"
android:layout_width="match_parent"
android:layout_height="40dp"
android:gravity="left"
android:textColor="#FB8C00"
android:textSize="20dp"/>

<TextView
android:id="@+id/tv6"
android:layout_width="match_parent"
android:layout_height="40dp"
android:gravity="left"
android:textColor="#FB8C00"
android:textSize="20dp"/>
<TextView
android:id="@+id/tv7"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginBottom="20dp"
android:gravity="left"
android:textColor="#FB8C00"
android:textSize="20dp"/>

<TextView
android:id="@+id/tv8"
android:layout_width="match_parent"
android:layout_height="40dp"
android:gravity="left"
android:textColor="#FB8C00"
android:textSize="20dp"/>

<TextView
android:id="@+id/tv9"
android:layout_width="match_parent"
android:layout_height="40dp"
android:gravity="left"
android:textColor="#FB8C00"
android:textSize="20dp"/>

<TextView
android:id="@+id/tv10"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginBottom="20dp"
android:gravity="left"
android:textColor="#FB8C00"
android:textSize="20dp"/>

<TextView
android:id="@+id/tv11"
android:layout_width="match_parent"
android:layout_height="40dp"
android:gravity="left"
android:textColor="#FB8C00"
android:textSize="20dp"/>

<TextView
android:id="@+id/tv12"
android:layout_width="match_parent"
android:layout_height="40dp"
android:gravity="left"
android:textColor="#FB8C00"
android:textSize="20dp"/>

<TextView
android:id="@+id/tv13"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginBottom="20dp"
android:gravity="left"
android:textColor="#FB8C00"
android:textSize="20dp"/>

<TextView
android:id="@+id/tv14"
android:layout_width="match_parent"
android:layout_height="40dp"
android:gravity="left"
android:textColor="#FB8C00"
android:textSize="20dp"/>

<TextView
android:id="@+id/tv15"
android:layout_width="match_parent"
android:layout_height="40dp"
android:gravity="left"
android:textColor="#FB8C00"
android:textSize="20dp"/>

<TextView
android:id="@+id/tv16"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginBottom="20dp"
android:gravity="left"
android:textColor="#FB8C00"
android:textSize="20dp"/>

<TextView
android:layout_width="match_parent"
android:layout_height="30dp"
android:text="LA COMPRA MAS ALTA ES"
android:gravity="center"/>

<TextView
android:id="@+id/tv17"
android:layout_width="match_parent"
android:layout_height="40dp"
android:gravity="left"
android:textColor="#FB8C00"
android:textSize="30dp"
android:layout_marginBottom="20dp"/>

</LinearLayout>
</ScrollView>

</LinearLayout>

MAINACTIVITY.JAVA

package com.example.actividad;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

Private EditText et1,et2,et3,et4,et5,et6;


private TextView
tv1,tv2,tv3,tv4,tv5,tv6,tv7,tv8,tv9,tv10,tv11,tv12,tv13,tv14,tv15,tv16,tv17,tv18,tv19,tv20;

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

et1=(EditText)findViewById(R.id.et1);
et2=(EditText)findViewById(R.id.et2);
et3=(EditText)findViewById(R.id.et3);
et4=(EditText)findViewById(R.id.et4);
et5=(EditText)findViewById(R.id.et5);
et6=(EditText)findViewById(R.id.et6);
tv2=(TextView)findViewById(R.id.tv2);
tv3=(TextView)findViewById(R.id.tv3);
tv4=(TextView)findViewById(R.id.tv4);
tv5=(TextView)findViewById(R.id.tv5);
tv6=(TextView)findViewById(R.id.tv6);
tv7=(TextView)findViewById(R.id.tv7);
tv8=(TextView)findViewById(R.id.tv8);
tv9=(TextView)findViewById(R.id.tv9);
tv10=(TextView)findViewById(R.id.tv10);
tv11=(TextView)findViewById(R.id.tv11);
tv12=(TextView)findViewById(R.id.tv12);
tv13=(TextView)findViewById(R.id.tv13);
tv14=(TextView)findViewById(R.id.tv14);
tv15=(TextView)findViewById(R.id.tv15);
tv16=(TextView)findViewById(R.id.tv16);
tv17=(TextView)findViewById(R.id.tv17);
tv18=(TextView)findViewById(R.id.tv18);
tv19=(TextView)findViewById(R.id.tv19);
tv20=(TextView)findViewById(R.id.tv20);
}

@Override public boolean onCreateOptionsMenu(Menu mimenu){


getMenuInflater().inflate(R.menu.menu_en_activity, mimenu);
return true;

@Override public boolean onOptionsItemSelected(MenuItem Opcion_Menu){


int id=Opcion_Menu.getItemId();

if(id==R.id.Cubo){
Intent i=new Intent(this, CuboNumero.class);
startActivity(i);

}
if(id==R.id.salir){
return true;
/*para ir a otra ventana
Intent i=new Intent(this, Ventas.Class);
startActivity(i);*/
}
return super.onOptionsItemSelected(Opcion_Menu);
}

public void calcular(View view){


String compra1=et1.getText().toString();
String compra2=et2.getText().toString();
String compra3=et3.getText().toString();
String compra4=et4.getText().toString();
String compra5=et5.getText().toString();
String compra6=et6.getText().toString();
float numero1=Float.parseFloat(compra1);
float numero2=Float.parseFloat(compra2);
float numero3=Float.parseFloat(compra3);
float numero4=Float.parseFloat(compra4);
float numero5=Float.parseFloat(compra5);
float numero6=Float.parseFloat(compra6);
//para la compra 1
float iva=numero1*19/100;
String resultadoiva=String.valueOf(iva);
tv3.setText("Total iva compra 1:$ "+resultadoiva);

float descuento;
if(numero1>100000){
descuento=numero1*10/100;
}else{
descuento=0;
}

String resultadodescuento=String.valueOf(descuento);
tv4.setText("Descuento compra 1:$ "+resultadodescuento);
float totalcompra1=numero1+(numero1*19/100)-descuento;
String resultadocompra1=String.valueOf(totalcompra1);
tv2.setText("Total Compra 1:$ "+resultadocompra1);

//para la compra 2
float iva2=numero2*19/100;
String resultadoiva2=String.valueOf(iva2);
tv6.setText("Total iva compra 2:$ "+resultadoiva2);

float descuento2;
if(numero2>100000){
descuento2=numero2*10/100;
}else{
descuento2=0;
}

String resultadodescuento2=String.valueOf(descuento2);
tv7.setText("Descuento compra 2:$ "+resultadodescuento2);
float totalcompra2=numero2+(numero2*19/100)-descuento2;
String resultadocompra2=String.valueOf(totalcompra2);
tv5.setText("Total compra 2:$ "+resultadocompra2);

//para la compra 3
float iva3=numero3*19/100;
String resultadoiva3=String.valueOf(iva3);
tv9.setText("Total iva compra 3:$ "+resultadoiva3);

float descuento3;
if(numero3>100000){
descuento3=numero3*10/100;
}else{
descuento3=0;
}

String resultadodescuento3=String.valueOf(descuento3);
tv10.setText("Descuento compra 3:$ "+resultadodescuento3);
float totalcompra3=numero3+(numero3*19/100)-descuento3;
String resultadocompra3=String.valueOf(totalcompra3);
tv8.setText("Total compra 3:$ "+resultadocompra3);

//para la compra 4
float iva4=numero4*19/100;
String resultadoiva4=String.valueOf(iva4);
tv12.setText("Total iva compra 4:$ "+resultadoiva4);

float descuento4;
if(numero4>100000){
descuento4=numero4*10/100;
}else{
descuento4=0;
}

String resultadodescuento4=String.valueOf(descuento4);
tv13.setText("Descuento compra 4:$ "+resultadodescuento4);
float totalcompra4=numero4+(numero4*19/100)-descuento4;
String resultadocompra4=String.valueOf(totalcompra4);
tv11.setText("Total compra 4:$ "+resultadocompra4);

//para la compra 5
float iva5=numero5*19/100;
String resultadoiva5=String.valueOf(iva5);
tv15.setText("Total iva compra 5:$ "+resultadoiva5);

float descuento5;
if(numero5>100000){
descuento5=numero5*10/100;
}else{
descuento5=0;
}

String resultadodescuento5=String.valueOf(descuento5);
tv16.setText("Descuento compra 5:$ "+resultadodescuento5);
float totalcompra5=numero5+(numero5*19/100)-descuento5;
String resultadocompra5=String.valueOf(totalcompra5);
tv14.setText("Total compra 5:$ "+resultadocompra5);

//para saber cual es la compra mas alta


if(totalcompra1>totalcompra2 && totalcompra1>totalcompra3 && totalcompra1>totalcompra4 &&
totalcompra1>totalcompra5){
tv17.setText("Compra 1:$ "+totalcompra1);
}else{
if(totalcompra2>totalcompra1 && totalcompra2>totalcompra3 && totalcompra2>totalcompra4
&& totalcompra2>totalcompra5){
tv17.setText("Compra 2:$ "+totalcompra2);
}else{
if(totalcompra3>totalcompra1 && totalcompra3>totalcompra2 &&
totalcompra3>totalcompra4 && totalcompra3>totalcompra5){
tv17.setText("Compra 3:$ "+totalcompra3);
}else{
if(totalcompra4>totalcompra1 && totalcompra4>totalcompra2 &&
totalcompra4>totalcompra3 && totalcompra4>totalcompra5){
tv17.setText("Compra 4:$ "+totalcompra4);
}else{
tv17.setText("Compra 5:$ "+totalcompra5);
}
}
}
}

También podría gustarte