0% found this document useful (0 votes)
14 views

Programação para Dispositivos Móveis AV1

The document describes an Android application that calculates the average of three grades entered by the user. It includes the XML layout code and Java code for the controller class that performs the calculation.

Uploaded by

santosweslley00
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

Programação para Dispositivos Móveis AV1

The document describes an Android application that calculates the average of three grades entered by the user. It includes the XML layout code and Java code for the controller class that performs the calculation.

Uploaded by

santosweslley00
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Universidade Veiga de almeida

SUPERIOR DE TECNOLOGIA EM ANÁLISE E


DESENVOLVIMENTO DE SISTEMAS

Programação para Dispositivos Móveis

Weslley Pereira dos Santos

CLAUDIO FICO FONSECA


código XML da View:

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

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

tools:context=".MainActivity">

<EditText

android:id="@+id/notaA1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:hint="Nota A1"

android:layout_marginTop="50dp"

android:layout_centerHorizontal="true"/>

<EditText

android:id="@+id/notaA2"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:hint="Nota A2"

android:layout_below="@id/notaA1"

android:layout_marginTop="20dp"

android:layout_centerHorizontal="true"/>

<EditText

android:id="@+id/notaA3"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:hint="Nota A3"
android:layout_below="@id/notaA2"

android:layout_marginTop="20dp"

android:layout_centerHorizontal="true"/>

<Button

android:id="@+id/calcular"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Calcular Média"

android:layout_below="@id/notaA3"

android:layout_marginTop="20dp"

android:layout_centerHorizontal="true"/>

<TextView

android:id="@+id/resultado"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text=""

android:textSize="20sp"

android:layout_below="@id/calcular"

android:layout_marginTop="20dp"

android:layout_centerHorizontal="true"/>

</RelativeLayout>

códigos Java® da Controller:

import android.os.Bundle;

import android.view.View;
import android.widget.Button;

import android.widget.EditText;

import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

private EditText notaA1, notaA2, notaA3;

private TextView resultado;

private Button calcular;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

notaA1 = findViewById(R.id.notaA1);

notaA2 = findViewById(R.id.notaA2);

notaA3 = findViewById(R.id.notaA3);

resultado = findViewById(R.id.resultado);

calcular = findViewById(R.id.calcular);

calcular.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

calcularMedia();

});

}
private void calcularMedia() {

// Obtendo as notas digitadas pelo usuário

double nota1 = Double.parseDouble(notaA1.getText().toString());

double nota2 = Double.parseDouble(notaA2.getText().toString());

double nota3 = Double.parseDouble(notaA3.getText().toString());

// Calculando a média

double media = (nota1 + nota2 + nota3) / 3;

// Exibindo o resultado

resultado.setText("Média Final: " + media);

You might also like