diff --git a/src/Main.java b/src/Main.java index c0dd6b0..e794f7a 100644 --- a/src/Main.java +++ b/src/Main.java @@ -1,34 +1,322 @@ import builders.StudentsBuilder; import entities.Studant; +import java.lang.reflect.Array; +import java.text.DecimalFormat; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; + public class Main { public static void main(String[] args) { + // O retorno do allStudents é uma List var allStudents = StudentsBuilder.getAllStudents(); - // Agora vamos as atividades + System.out.println("Exercício 1"); + DecimalFormat formatador = new DecimalFormat("0.00"); /* - 1. Recupere da lista os alunos que passaram de ano (nota minima 7.0). - - Exiba os dados nesse formato: - : Média = + - Exiba os dados nesse formato: - : Média = */ + System.out.println("Alunos que passaram de ano"); + for (Studant students : allStudents) { + float nota = (students.getTestOne() + students.getTestTwo() + students.getTestThree()) / 3; + if (nota >= 7) { + System.out.println(students.getCode() + " Nome :" + students.getName() + "Média = " + formatador.format(nota)); + } + } + + System.out.println(); + System.out.println("Exercício 2"); + + /* 2. Recupere da lista os alunos que não passaram de ano. - - Exiba os dados nesse formato: - : Média = (Faltou = ) + - Exiba os dados nesse formato: - : Média = (Faltou = )*/ + System.out.println(); + System.out.println(" Não aprovados"); + for (Studant students : allStudents) { + float nota = (students.getTestOne() + students.getTestTwo() + students.getTestThree()) / 3; + if (nota < 7) { + System.out.println(students.getCode() + " Nome :" + students.getName() + " Média = " + formatador.format(nota) + " Faltou = " + formatador.format(7 - nota)); + } + } + System.out.println(); + System.out.println("Exercício 3"); + System.out.println(); + /* 3. Traga os alunos que tiraram a nota máxima (nota 10). - - Exiba os dados nesse formato: - - 4. Traga o aluno que tirou a menor nota, em caso de notas iguais, traga ambos os alunos. - - Exiba os dados nesse formato: - : Nota = + - Exiba os dados nesse formato: - */ + + System.out.println(); + System.out.println("Alunos que tiraram nota máxima"); + System.out.println(); + for (Studant students : allStudents) { + + if (students.getTestOne() == 10 || students.getTestTwo() == 10 || students.getTestThree() == 10) { + System.out.println(students.getCode() + " Nome :" + students.getName()); + } + } + + + System.out.println(); + System.out.println("Exercício 4"); + System.out.println(); + /* 4. Traga o aluno que tirou a menor nota, em caso de notas iguais, traga ambos os alunos. + - Exiba os dados nesse formato: - : Nota = */ + + double menorNota = Double.MAX_VALUE; + for (Studant students : allStudents) { + + if (menorNota > students.getTestOne() || students.getTestTwo() > menorNota || students.getTestThree() > menorNota) { + + if (students.getTestOne() < menorNota && students.getTestOne() < students.getTestTwo() && students.getTestOne() < students.getTestThree()) { + menorNota = students.getTestOne(); + } else { + if (students.getTestTwo() < menorNota && students.getTestTwo() < menorNota && students.getTestTwo() < students.getTestOne() && students.getTestTwo() < students.getTestThree()) { + menorNota = students.getTestTwo(); + } else { + if (students.getTestThree() < menorNota && students.getTestThree() < menorNota && students.getTestThree() < students.getTestOne() && students.getTestThree() < students.getTestTwo()) { + menorNota = students.getTestThree(); + } + } + } + + } + + + } + for (Studant students : allStudents) { + + if (menorNota == students.getTestOne() || students.getTestTwo() == menorNota || students.getTestThree() == menorNota) { + System.out.println(students.getCode() + " Nome :" + students.getName() + " Nota " + formatador.format(menorNota)); + } + } + + + System.out.println(); + System.out.println("Exercício 5"); + System.out.println(); + /* 5. Faça uma lista com top 3 notas de alunos. Em caso de notas iguais coloque todos na mesma posição. - Ex: 1º - Fulano : Nota = 10.0; - Beltrano : Nota = 10.0; 2º - Joãozinho : Nota = 9.0; 3º - Mariazinha : Nota = 8.9; - - Exiba os dados nesse formato: - : Nota = - 6. Faça uma lista com as 3 menores notas de alunos. Em caso de notas iguais coloque todos na mesma posição. Exemplo igual a anterior - - Exiba os dados nesse formato: - : Nota = - 7. Monte a média de todos os alunos e exiba em tela ordenando da maior para a menor nota. + - Exiba os dados nesse formato: - : Nota = */ + + ArrayList listNota = new ArrayList(); + float notaone = Float.MIN_VALUE; + float notatwo = Float.MIN_VALUE; + float notaThree = Float.MIN_VALUE; + for (Studant students : allStudents) { + if (students.getTestOne() > notaone) { + notaThree = notatwo; + notatwo = notaone; + notaone = students.getTestOne(); + } + if (students.getTestTwo() > notaone) { + notaThree = notatwo; + notatwo = notaone; + notaone = students.getTestTwo(); + } + if (students.getTestThree() > notaone) { + notaThree = notatwo; + notatwo = notaone; + notaone = students.getTestThree(); + } + if (students.getTestOne() > notatwo && students.getTestOne() < notaone) { + notaThree = notatwo; + notatwo = students.getTestOne(); + } + if (students.getTestTwo() > notatwo && students.getTestTwo() < notaone) { + notaThree = notatwo; + notatwo = students.getTestTwo(); + } + if (students.getTestThree() > notatwo && students.getTestThree() < notaone) { + notaThree = notatwo; + notatwo = students.getTestThree(); + } + if (students.getTestOne() > notaThree && students.getTestOne() < notaone && students.getTestOne() < notatwo) { + notaThree = students.getTestOne(); + } + if (students.getTestTwo() > notaThree && students.getTestTwo() < notaone && students.getTestTwo() < notatwo) { + notaThree = students.getTestTwo(); + } + if (students.getTestThree() > notaThree && students.getTestThree() < notaone && students.getTestThree() < notatwo) { + notaThree = students.getTestThree(); + } + + + } + + + int i = 0; + + // + for (Studant students : allStudents) { + + if (students.getTestOne() == notaone || students.getTestTwo() == notaone || students.getTestThree() == notaone) { + if (i == 0) { + System.out.println(i + "º - " + students.getName() + " :" + "Nota = " + formatador.format(notaone)); + i++; + } else { + System.out.println(" " + " - " + students.getName() + " :" + "Nota = " + formatador.format(notaone)); + } + } + + } + for (Studant students : allStudents) { + + if (students.getTestOne() == notatwo || students.getTestTwo() == notatwo || students.getTestThree() == notatwo) { + if (i == 1) { + System.out.println(i + "º - " + students.getName() + " :" + "Nota = " + formatador.format(notatwo)); + i++; + } else { + System.out.println(" " + " - " + students.getName() + " :" + "Nota = " + formatador.format(notatwo)); + } + } + + } + for (Studant students : allStudents) { + + if (students.getTestOne() == notaThree || students.getTestTwo() == notaThree || students.getTestThree() == notaThree) { + if (i == 2) { + System.out.println(i + "º - " + students.getName() + " :" + "Nota = " + formatador.format(notaThree)); + i++; + } else { + System.out.println(" " + " - " + students.getName() + " :" + "Nota = " + formatador.format(notaThree)); + } + } + + } + + + System.out.println(); + System.out.println("Exercício 6"); + System.out.println(); + + /* 6. Faça uma lista com as 3 menores notas de alunos. Em caso de notas iguais coloque todos na mesma posição. Exemplo igual a anterior + - Exiba os dados nesse formato: - : Nota = */ + + ArrayList listNotaMenores = new ArrayList(); + float notamenor1 = Float.MAX_VALUE; + float notamenor2 = Float.MAX_VALUE; + float notamenor3 = Float.MAX_VALUE; + System.out.println("Menores notas"); + for (Studant students : allStudents) { + if (students.getTestOne() < notamenor1) { + notamenor3 = notamenor2; + notamenor2 = notamenor1; + notamenor1 = students.getTestOne(); + } + if (students.getTestTwo() < notamenor1) { + notamenor3 = notamenor2; + notamenor2 = notamenor1; + notamenor1 = students.getTestTwo(); + } + if (students.getTestThree() < notamenor1) { + notamenor3 = notamenor2; + notamenor2 = notamenor1; + notamenor1 = students.getTestThree(); + } + if (students.getTestOne() < notamenor2 && students.getTestOne() > notamenor1) { + notamenor3 = notamenor2; + notamenor2 = students.getTestOne(); + } + if (students.getTestTwo() < notamenor2 && students.getTestTwo() > notamenor1) { + notamenor3 = notamenor2; + notamenor2 = students.getTestTwo(); + } + if (students.getTestThree() < notamenor2 && students.getTestThree() > notamenor1) { + notamenor3 = notatwo; + notamenor2 = students.getTestThree(); + } + if (students.getTestOne() notamenor1 && students.getTestOne() > notamenor2) { + notamenor3 = students.getTestOne(); + } + if (students.getTestTwo() < notamenor3 && students.getTestTwo() > notamenor1 && students.getTestTwo() > notamenor2) { + notamenor3 = students.getTestTwo(); + } + if (students.getTestThree() < notamenor3 && students.getTestThree() > notamenor1 && students.getTestThree() > notamenor2) { + notamenor3 = students.getTestThree(); + } + + + } + + int j = 0; + + // + for (Studant students : allStudents) { + if (students.getTestOne() == notamenor1 ||students.getTestTwo() == notamenor1 || students.getTestThree() == notamenor1) { + if (j == 0) { + System.out.println(j + "º - " + students.getName() + " :" + "Nota = " + formatador.format(notamenor1)); + j++; + } else { + System.out.println(" " + " - " + students.getName() + " :" + "Nota = " + formatador.format(notamenor1)); + } + } + + } + for (Studant students : allStudents) { + + if (students.getTestOne() == notamenor2 ||students.getTestTwo() == notamenor2 || students.getTestThree() == notamenor2) { + if (j == 1) { + System.out.println(j + "º - " + students.getName() + " :" + "Nota = " + formatador.format(notamenor2)); + j++; + } else { + System.out.println(" " + " - " + students.getName() + " :" + "Nota = " + formatador.format(notamenor2)); + } + } + + } + for ( + Studant students : allStudents) { + + if (students.getTestOne() == notamenor3 ||students.getTestTwo() == notamenor3 || students.getTestThree() == notamenor3) { + if (j == 2) { + System.out.println(j + "º - " + students.getName() + " :" + "Nota = " + formatador.format(notamenor3)); + j++; + } else { + System.out.println(" " + " - " + students.getName() + " :" + "Nota = " + formatador.format(notamenor3)); + } + } + + } + + + /* 7. Monte a média de todos os alunos e exiba em tela ordenando da maior para a menor nota. - Exiba os dados nesse formato: - - : Média = - */ + */ + System.out.println(); + System.out.println("Exercício 7"); + System.out.println(); + ArrayList listNotas = new ArrayList(); + for ( + Studant students : allStudents) { + float nota = (students.getTestOne() + students.getTestTwo() + students.getTestThree()) / 3; + + listNotas.add(nota); + + } + + int k = 0; + int l = 0; + Collections.sort(listNotas, Collections.reverseOrder()); + + + while (l < listNotas.size()) { + for (Studant students : allStudents) { + float nota = (students.getTestOne() + students.getTestTwo() + students.getTestThree()) / 3; + if (nota == listNotas.get(l)) { + System.out.println(l + " - " + students.getName() + " :" + "Nota = " + formatador.format(nota)); + } + } + l++; + } } } + diff --git a/src/builders/StudentsBuilder.java b/src/builders/StudentsBuilder.java index d68f333..c7fa9b3 100644 --- a/src/builders/StudentsBuilder.java +++ b/src/builders/StudentsBuilder.java @@ -8,14 +8,15 @@ public abstract class StudentsBuilder { public static List getAllStudents() { return List.of( - new Studant(1, "Aluno 1", 6.0f, 7.8f, 7.4f), - new Studant(2, "Aluno 2", 8.0f, 5.0f, 9.9f), - new Studant(3, "Aluno 3", 6.6f, 6.6f, 6.4f), - new Studant(4, "Aluno 4", 6.7f, 7.9f, 10.0f), - new Studant(5, "Aluno 5", 6.1f, 4.4f, 5.7f), - new Studant(6, "Aluno 6", 7.3f, 7.3f, 8.8f), - new Studant(7, "Aluno 7", 8.2f, 8.2f, 9.9f), - new Studant(8, "Aluno 8", 10.0f, 9.1f, 7.7f) + new Studant(1, "Aluno 1", 6.0f, 7.8f, 7.4f), + new Studant(2, "Aluno 2", 8.0f, 5.0f, 9.9f), + new Studant(3, "Aluno 3", 6.6f, 6.6f, 6.4f), + new Studant(4, "Aluno 4", 6.7f, 7.9f, 10.0f), + new Studant(5, "Aluno 5", 6.1f, 4.4f, 5.7f), + new Studant(6, "Aluno 6", 7.3f, 7.3f, 8.8f), + new Studant(7, "Aluno 7", 8.2f, 8.2f, 9.9f), + new Studant(8, "Aluno 8", 10.0f, 9.1f, 7.7f) + ); } } diff --git a/src/entities/Studant.java b/src/entities/Studant.java index faf8c8e..4d29391 100644 --- a/src/entities/Studant.java +++ b/src/entities/Studant.java @@ -1,11 +1,10 @@ package entities; -import java.util.List; public class Studant { private int code; - private String name; + private String name; private float testOne; private float testTwo; private float testThree;