From 9ec002e29d2834a0a282e7afdcfb7fc382ad3b2e Mon Sep 17 00:00:00 2001 From: TiagoRG <35657250+TiagoRG@users.noreply.github.com> Date: Mon, 27 Feb 2023 17:41:01 +0000 Subject: [PATCH] Created a new version for grades to be random --- 1ano/2semestre/poo/src/aula03/Grades.java | 2 +- .../poo/src/aula03/GradesRandom.java | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 1ano/2semestre/poo/src/aula03/GradesRandom.java diff --git a/1ano/2semestre/poo/src/aula03/Grades.java b/1ano/2semestre/poo/src/aula03/Grades.java index 4af54d7..c3426a4 100644 --- a/1ano/2semestre/poo/src/aula03/Grades.java +++ b/1ano/2semestre/poo/src/aula03/Grades.java @@ -3,7 +3,7 @@ package aula03; import java.util.Scanner; import utils.UserInput; -// Solução do exercício 4 +// Solução do exercício 4 com o utilizador a introduzir as notas individualmente public class Grades { private static final Scanner sin = new Scanner(System.in); diff --git a/1ano/2semestre/poo/src/aula03/GradesRandom.java b/1ano/2semestre/poo/src/aula03/GradesRandom.java new file mode 100644 index 0000000..3ee3ad8 --- /dev/null +++ b/1ano/2semestre/poo/src/aula03/GradesRandom.java @@ -0,0 +1,24 @@ +package aula03; + + +// Solução do exercício 4 com notas aleatórias + +import java.util.Random; +import java.util.Scanner; + +public class GradesRandom { + private static final Scanner sin = new Scanner(System.in); + private static final Random rand = new Random(); + + public static void main(String[] args) { + System.out.print("Quantos alunos tem a turma? "); + int studentCount = sin.nextInt(); + + System.out.println("NotaT NotaP Pauta"); + for (int i = 0; i < studentCount; i++) { + double notaT = rand.nextDouble(0, 20); + double notaP = rand.nextDouble(0, 20); + System.out.printf("%5.1f %5.1f %5d\n", notaT, notaP, (notaT < 7 || notaP < 7) ? 66 : (int) Math.round(0.4 * notaT + 0.6 * notaP)); + } + } +}