You are on page 1of 5

Activity_Main.

xml

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


<androidx.constraintlayout.widget.ConstraintLayout
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">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<TextView
android:id="@+id/cmdNombres"
android:layout_width="21dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Nombres" />

<EditText
android:id="@+id/txtNombres"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="textPersonName" />

</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<TextView
android:id="@+id/cdmMateria1"
android:layout_width="86dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Materia1:" />

<EditText
android:id="@+id/txtMateria1"
android:layout_width="88dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="textPersonName" />
<TextView
android:id="@+id/cmdPorcentaje1"
android:layout_width="88dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Porcentaje1:" />

<EditText
android:id="@+id/txtPorcentaje1"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="textPersonName" />

</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal">

<TextView
android:id="@+id/cdmMateria2"
android:layout_width="90dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Materia2:" />

<EditText
android:id="@+id/txtMateria2"
android:layout_width="95dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="textPersonName" />

<TextView
android:id="@+id/cmdPorcentaje2"
android:layout_width="86dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Porcentaje 2:" />

<EditText
android:id="@+id/txtPorcentaje2"
android:layout_width="104dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="textPersonName" />
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="278dp"
android:orientation="horizontal">
<Button
android:id="@+id/cdmCalcular"
android:layout_width="105dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="Calcular"
android:text="Calcular" />

<Button
android:id="@+id/cdmLimpiar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="limpiar"
android:text="Limpiar" />
</LinearLayout>

</LinearLayout>

</androidx.constraintlayout.widget.ConstraintLayout>

***********************************************************************************
***********************************************************************************
***********************************************************************************
***********************************************************************************
**

MainActivity.java

package edu.uniciencia.trabajonmovil;

import androidx.appcompat.app.AppCompatActivity;

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

public class MainActivity extends AppCompatActivity {

private EditText txtNombres;


private EditText txtMateria1;
private EditText txtPorcentaje1;
private EditText txtMateria2;
private EditText txtPorcentaje2;

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

txtNombres = findViewById(R.id.txtNombres);
txtMateria1 = findViewById(R.id.txtMateria1);
txtPorcentaje1 = findViewById(R.id.txtPorcentaje1);
txtMateria2 = findViewById(R.id.txtMateria2);
txtPorcentaje2 = findViewById(R.id.txtPorcentaje2);
}
public void Calcular(View view){
String valor = txtNombres.getText().toString();
String valor1 = txtMateria1.getText().toString();
String valor2 = txtPorcentaje1.getText().toString();
String valor3 = txtMateria2.getText().toString();
String valor4 = txtPorcentaje2.getText().toString();

double mat1 = Double.parseDouble(valor1);


double por1 = Double.parseDouble(valor2);
double mat2 = Double.parseDouble(valor3);
double por2 = Double.parseDouble(valor4);
double resultado1 = mat1*por1;
double resultado2 = mat2*por2;
double resultadofinal = resultado1+resultado2;

Intent intent = new Intent(this,Actividad2.class);


intent.putExtra("Resultados",resultadofinal+"");
startActivity(intent);
}
public void limpiar(View v){

txtNombres.setText("");
txtMateria1.setText("");
txtPorcentaje1.setText("");
txtMateria2.setText("");
txtPorcentaje2.setText("");
}
}

***********************************************************************************
***********************************************************************************
***********************************************************************************
***********************************************************************************
**

Activity_actividad2.xml

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


<androidx.constraintlayout.widget.ConstraintLayout
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=".Actividad2">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<TextView
android:id="@+id/txtResultado"
android:layout_width="match_parent"
android:layout_height="133dp" />

<Button
android:id="@+id/cdmCerrar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="cerrarActividad"
android:text="Cerrar" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

***********************************************************************************
***********************************************************************************
***********************************************************************************
***********************************************************************************
**

package edu.uniciencia.trabajonmovil;

import androidx.appcompat.app.AppCompatActivity;

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

public class Actividad2 extends AppCompatActivity {

TextView txt = null;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_actividad2);
txt= findViewById(R.id.txtResultado);
Bundle parametros = getIntent().getExtras();
String valor = parametros.getString("Resultados");
Toast toast = Toast.makeText(this,valor, Toast.LENGTH_SHORT);
toast.show();
txt.setText(valor);
}
public void cerrarActividad(View view){
finish();
}
}

You might also like