Prévia do material em texto
UNIVERSIDADE VEIGA DE ALMEIDA
SISTEMAS DE INFORMAÇÃO
Programação Para Dispositivos Móveis
AVA1
Professor Thiago Alberto Ramos Gabriel
Aluna: Elen Pires de Araújo
Mat.: 20203301257
Nova Iguaçu
Agosto de 2021
INTRODUÇÃO
O presente documento tem por objetivo atender o que foi solicitado no
trabalho de avaliação 1, que comporá a nota A1. Para melhor leitura do código
disponibilizei os dois arquivos no Gist, links na conclusão.
ENUNCIADO
Desenvolvimento de um aplicativo para o cálculo da média das disciplinas EaD
Analise o procedimento para o cálculo da média de sua disciplina e crie uma
aplicação (app) que seja capaz de receber as notas de A1, A2 e A3 de um aluno e
apresentar sua média final na disciplina. Um aluno precisa calcular a média obtida
em uma disciplina EaD na nossa instituição, mas não sabe exatamente como fazer
isso. O aluno em questão é um exemplo de usuário para uma aplicação que solicite
as notas de A1, A2 e A3 e apresente sua média.
DESENVOLVIMENTO
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 " >
< TextView
android : id = " @+id/titleCalculadoraMedia "
android : layout_width = " wrap_content "
android : layout_height = " wrap_content "
android : layout_marginTop = " 29dp "
android : text = " CALCULADORA DE MÉDIA "
android : textSize = " 24sp "
android : textStyle = " bold "
app : layout_constraintEnd_toEndOf = " parent "
app : layout_constraintStart_toStartOf = " parent "
app : layout_constraintTop_toTopOf = " parent " />
< EditText
android : id = " @+id/inputA1 "
android : layout_width = " 0dp "
android : layout_height = " 42dp "
android : layout_marginEnd = " 57dp "
android : layout_marginRight = " 57dp "
android : ems = " 10 "
android : inputType = " numberDecimal "
app : layout_constraintBaseline_toBaselineOf = " @+id/labelA1 "
app : layout_constraintEnd_toEndOf = " parent "
app : layout_constraintStart_toEndOf = " @+id/labelA1 " />
< EditText
android : id = " @+id/inputA3 "
android : layout_width = " 0dp "
android : layout_height = " 42dp "
android : layout_marginEnd = " 59dp "
android : layout_marginRight = " 59dp "
android : ems = " 10 "
android : inputType = " numberDecimal "
app : layout_constraintBaseline_toBaselineOf = " @+id/labelA3 "
app : layout_constraintEnd_toEndOf = " parent "
app : layout_constraintStart_toEndOf = " @+id/labelA3 " />
< TextView
android : id = " @+id/labelA3 "
android : layout_width = " wrap_content "
android : layout_height = " wrap_content "
android : layout_marginStart = " 65dp "
android : layout_marginLeft = " 65dp "
android : layout_marginTop = " 209dp "
android : text = " Nota da A3: "
app : layout_constraintEnd_toStartOf = " @+id/inputA3 "
app : layout_constraintStart_toStartOf = " parent "
app : layout_constraintTop_toBottomOf = " @+id/titleCalculadoraMedia "
/>
< TextView
android : id = " @+id/labelResultado "
android : layout_width = " wrap_content "
android : layout_height = " wrap_content "
android : layout_marginStart = " 65dp "
android : layout_marginLeft = " 65dp "
android : layout_marginTop = " 45dp "
android : text = " Nota final: "
android : textSize = " 20sp "
android : textStyle = " bold "
app : layout_constraintStart_toStartOf = " parent "
app : layout_constraintTop_toBottomOf = " @+id/calculate " />
< Button
android : id = " @+id/calculate "
android : layout_width = " wrap_content "
android : layout_height = " wrap_content "
android : layout_marginStart = " 65dp "
android : layout_marginLeft = " 65dp "
android : layout_marginTop = " 40dp "
android : onClick = " calcular "
android : text = " Calcular "
app : backgroundTint = " @color/teal_700 "
app : layout_constraintStart_toStartOf = " parent "
app : layout_constraintTop_toBottomOf = " @+id/textAviso " />
< Button
android : id = " @+id/button2 "
android : layout_width = " wrap_content "
android : layout_height = " wrap_content "
android : layout_marginStart = " 80dp "
android : layout_marginLeft = " 80dp "
android : layout_marginTop = " 40dp "
android : onClick = " limpar "
android : text = " Limpar "
app : backgroundTint = " ?attr/colorError "
app : layout_constraintStart_toEndOf = " @+id/calculate "
app : layout_constraintTop_toBottomOf = " @+id/textAviso " />
< EditText
android : id = " @+id/inputA2 "
android : layout_width = " 0dp "
android : layout_height = " 42dp "
android : layout_marginEnd = " 59dp "
android : layout_marginRight = " 59dp "
android : ems = " 10 "
android : inputType = " numberDecimal "
app : layout_constraintBaseline_toBaselineOf = " @+id/labelA2 "
app : layout_constraintEnd_toEndOf = " parent "
app : layout_constraintStart_toEndOf = " @+id/labelA2 " />
< TextView
android : id = " @+id/labelA2 "
android : layout_width = " wrap_content "
android : layout_height = " wrap_content "
android : layout_marginStart = " 65dp "
android : layout_marginLeft = " 65dp "
android : layout_marginTop = " 129dp "
android : text = " Nota da A2: "
app : layout_constraintEnd_toStartOf = " @+id/inputA2 "
app : layout_constraintStart_toStartOf = " parent "
app : layout_constraintTop_toBottomOf = " @+id/titleCalculadoraMedia "
/>
< TextView
android : id = " @+id/labelCampoObrigatorio2 "
android : layout_width = " wrap_content "
android : layout_height = " wrap_content "
android : layout_marginStart = " 2dp "
android : layout_marginLeft = " 2dp "
android : text = " Campo obrigatório "
android : textColor = " #C6C1C1 "
android : textSize = " 10sp "
android : textStyle = " italic "
app : layout_constraintBottom_toBottomOf = " @+id/inputA2 "app : layout_constraintStart_toStartOf = " @+id/inputA2 "
app : layout_constraintTop_toBottomOf = " @+id/inputA2 " />
< TextView
android : id = " @+id/labelA1 "
android : layout_width = " wrap_content "
android : layout_height = " wrap_content "
android : layout_marginStart = " 65dp "
android : layout_marginLeft = " 65dp "
android : layout_marginTop = " 49dp "
android : layout_marginEnd = " 2dp "
android : layout_marginRight = " 2dp "
android : text = " Nota da A1: "
app : layout_constraintEnd_toStartOf = " @+id/inputA1 "
app : layout_constraintStart_toStartOf = " parent "
app : layout_constraintTop_toBottomOf = " @+id/titleCalculadoraMedia "
/>
< TextView
android : id = " @+id/labelCampoObrigatorio1 "
android : layout_width = " wrap_content "
android : layout_height = " wrap_content "
android : layout_marginStart = " 2dp "
android : layout_marginLeft = " 2dp "
android : text = " Campo obrigatório "
android : textColor = " #C6C1C1 "
android : textSize = " 10sp "
android : textStyle = " italic "
app : layout_constraintBottom_toBottomOf = " @+id/inputA1 "
app : layout_constraintStart_toStartOf = " @+id/inputA1 "
app : layout_constraintTop_toBottomOf = " @+id/inputA1 " />
< TextView
android : id = " @+id/textResultado "
android : layout_width = " wrap_content "
android : layout_height = " wrap_content "
android : layout_marginStart = " 165dp "
android : layout_marginLeft = " 165dp "
android : layout_marginTop = " 45dp "
android : textColor = " #673AB7 "
android : textSize = " 20sp "
android : textStyle = " bold "
app : layout_constraintStart_toStartOf = " parent "
app : layout_constraintTop_toBottomOf = " @+id/calculate " />
< TextView
android : id = " @+id/textAviso "
android : layout_width = " wrap_content "
android : layout_height = " wrap_content "
android : layout_marginStart = " 65dp "
android : layout_marginLeft = " 65dp "
android : layout_marginTop = " 40dp "
android : textColor = " #F40505 "
android : textSize = " 11sp "
android : textStyle = " bold "
app : layout_constraintStart_toStartOf = " parent "
app : layout_constraintTop_toBottomOf = " @+id/inputA3 " />
< androidx.constraintlayout.widget.Guideline
android : id = " @+id/guideline2 "
android : layout_width = " wrap_content "
android : layout_height = " wrap_content "
android : orientation = " vertical "
app : layout_constraintGuide_begin = " 20dp " />
</ androidx.constraintlayout.widget.ConstraintLayout >
MainActivity.java
package com.example.calculadoramedia ;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
EditText notaA1, notaA2, notaA3;
TextView resultado, aviso;
@ Override
protected void onCreate ( Bundle savedInstanceState ) {
super . onCreate (savedInstanceState);
setContentView (R.layout.activity_main);
notaA1 = (EditText) findViewById (R.id.inputA1);
notaA2 = (EditText) findViewById (R.id.inputA2);
notaA3 = (EditText) findViewById (R.id.inputA3);
resultado = (TextView) findViewById (R.id.textResultado);
aviso = (TextView) findViewById (R.id.textAviso);
}
public void calcular ( View v ) {
String n1 = notaA1. getText (). toString ();
String n2 = notaA2. getText (). toString ();
String n3 = notaA3. getText (). toString ();
if ( ! n1. isEmpty () && ! n2. isEmpty ()) {
aviso. setText ( "" );
float nota1 = Float. parseFloat (n1);
float nota2 = Float. parseFloat (n2);
float maiorNota = nota2;
if ( ! n3. isEmpty ()) {
float nota3 = Float. parseFloat (n3);
if (nota3 > nota2) maiorNota = nota3;
}
if (nota1 < 0.1 || maiorNota < 5 ) {
double notaFinal = (nota1 * 0.4 ) + (maiorNota * 0.6 )
/ 2 ;
resultado. setText (String. format ( " %,.2f " ,
notaFinal) + " - Reprovado " );
} else {
double notaFinal = (nota1 * 0.4 ) + (maiorNota * 0.6 );
if (notaFinal >= 6 ) {
resultado. setText (String. format ( " %,.2f " ,
notaFinal) + " - Aprovado " );
} else {
resultado. setText (String. format ( " %,.2f " ,
notaFinal) + " - Reprovado " );
}
}
} else {
resultado. setText ( "" );
aviso. setText ( " Os campos \" Nota da A1 \" e \" Nota da
\" A2 \" são obrigatórios " );
}
}
public void limpar ( View v ) {
notaA1. setText ( "" );
notaA2. setText ( "" );
notaA3. setText ( "" );
resultado. setText ( "" );
aviso. setText ( "" );
}
}
CONCLUSÃO
O projeto criado é funcional e se encontra disponível no Github através do
link: https://github.com/elenaraujo/mobile-calculadora-media .
Para melhor leitura, os dois arquivos acima também foram disponibilizados
via gist através do link:
https://gist.github.com/elenaraujo/523f7597099fbf7443be9efc3009a331
https://github.com/elenaraujo/mobile-calculadora-media
https://gist.github.com/elenaraujo/523f7597099fbf7443be9efc3009a331
REFERÊNCIAS
Build Your First Android App in Java - Google Developers
< https://developer.android.com/codelabs/build-your-first-android-app#0 > - Acesso
em 30 de agosto de 2021
Guia Completo de Android: Básico ao Avançado em Android - DevMedia
< https://www.devmedia.com.br/guia/android/34580 > - Acesso em 30 de agosto de
2021.
Tutorial de Android Studio - DevMedia
< https://www.devmedia.com.br/tutorial-de-android-studio/34003 > - Acesso em 30 de
agosto de 2021.
https://developer.android.com/codelabs/build-your-first-android-app#0
https://www.devmedia.com.br/guia/android/34580
https://www.devmedia.com.br/tutorial-de-android-studio/34003