Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ui;
- import java.util.Scanner;
- /**
- *
- * @author piteru-san
- */
- public class ExamenApplicatie
- {
- private int aantalExamens = 5;
- public static void main(String[] args)
- {
- int[][] examens = new int[2][5];
- int[] percentages = new int[2];
- voerExamensAlleStudentenIn(examens);
- berekenPercentage(examens, percentages);
- System.out.printf("%s%ngemiddelde: %.2f%n", maakUitvoer(examens, percentages), berekenGemiddeldPercentage(percentages));
- }
- private static void voerExamensAlleStudentenIn(int[][] array)
- {
- Scanner s = new Scanner(System.in);
- int aantalExamens;
- for(int index = 0; index < array.length; index++)
- {
- do
- {
- System.out.printf("Hoeveel examens heeft student %d afgelegd (max = 5): ", index + 1);
- aantalExamens = s.nextInt();
- }
- while(aantalExamens < 0 || aantalExamens > 5);
- int[] array2 = new int[aantalExamens];
- voerPuntenPerStudentIn(array2);
- array[index] = array2;
- }
- }
- private static void voerPuntenPerStudentIn(int[] array)
- {
- Scanner s = new Scanner(System.in);
- for(int index = 0; index < array.length; index++)
- {
- do
- {
- System.out.printf("Examen %d (op 20): ", index+1);
- array[index] = s.nextInt();
- }
- while(array[index] < 0 || array[index] > 20);
- }
- }
- public static void berekenPercentage(int[][] examen, int[] percentages)
- {
- for(int index = 0; index < examen.length; index++)
- {
- int totaal = 0;
- int percentage;
- for(int index2 = 0; index2 < examen[index].length; index2++)
- {
- totaal += examen[index][index2];
- }
- percentage = (totaal*100/(examen[index].length*20));
- percentages[index] = percentage;
- }
- }
- private static String maakUitvoer(int[][] examen, int[] percentages)
- {
- String s = "";
- for(int index = 0; index < examen.length; index++)
- {
- s += String.format("Student %d", index + 1);
- int controle = 0;
- for(int index2 = 0; index2 < examen[index].length; index2++)
- {
- if(examen[index][index2] < 10)
- controle++;
- s += String.format("%10d", examen[index][index2]);
- }
- s += String.format("%npercentage : %d %s%n", percentages[index], (percentages[index] >= 60 && controle == 0) ? "Geslaagd" : "Niet geslaagd");
- }
- return s;
- }
- public static double berekenGemiddeldPercentage(int[] percentages)
- {
- int totaal = 0;
- double gemiddelde;
- for(int index = 0; index < percentages.length; index++)
- {
- totaal += percentages[index];
- }
- gemiddelde = totaal/percentages.length;
- return gemiddelde;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement