Actividad de App 2
Actividad de App 2
FACULTAD DE INGENIERÍA
PROGRAMA EDUCATIVO
INGENIERÍA DE SOFTWARE
DESARROLLO DE APP
INSTRUCTOR:
MARTIN INDABURO
ESTUDIANTES:
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
<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;
@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();
}
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();
}
}
}
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
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;
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);
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
<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;
@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);
}
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);
}
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);