Created a new version for grades to be random

This commit is contained in:
TiagoRG 2023-02-27 17:41:01 +00:00
parent d07c95409e
commit 9ec002e29d
Signed by untrusted user who does not match committer: TiagoRG
GPG Key ID: DFCD48E3F420DB42
2 changed files with 25 additions and 1 deletions

View File

@ -3,7 +3,7 @@ package aula03;
import java.util.Scanner; import java.util.Scanner;
import utils.UserInput; 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 { public class Grades {
private static final Scanner sin = new Scanner(System.in); private static final Scanner sin = new Scanner(System.in);

View File

@ -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));
}
}
}