Advertisement
Guest User

H6/H8 (deel2) - Oefening 4

a guest
Jan 16th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.23 KB | None | 0 0
  1. package ui;
  2.  
  3. import java.util.Scanner;
  4.  
  5. /**
  6.  *
  7.  * @author piteru-san
  8.  */
  9. public class ExamenApplicatie
  10. {
  11.     private int aantalExamens = 5;
  12.    
  13.     public static void main(String[] args)
  14.     {
  15.         int[][] examens = new int[2][5];
  16.         int[] percentages = new int[2];
  17.        
  18.         voerExamensAlleStudentenIn(examens);
  19.         berekenPercentage(examens, percentages);
  20.         System.out.printf("%s%ngemiddelde: %.2f%n", maakUitvoer(examens, percentages), berekenGemiddeldPercentage(percentages));
  21.     }
  22.    
  23.     private static void voerExamensAlleStudentenIn(int[][] array)
  24.     {
  25.         Scanner s = new Scanner(System.in);
  26.         int aantalExamens;
  27.        
  28.         for(int index = 0; index < array.length; index++)
  29.         {
  30.             do
  31.             {
  32.             System.out.printf("Hoeveel examens heeft student %d afgelegd (max = 5): ", index + 1);
  33.             aantalExamens = s.nextInt();
  34.             }
  35.             while(aantalExamens < 0 || aantalExamens > 5);
  36.            
  37.             int[] array2 = new int[aantalExamens];
  38.            
  39.             voerPuntenPerStudentIn(array2);
  40.            
  41.             array[index] = array2;
  42.         }
  43.     }
  44.    
  45.     private static void voerPuntenPerStudentIn(int[] array)
  46.     {
  47.         Scanner s = new Scanner(System.in);
  48.        
  49.         for(int index = 0; index < array.length; index++)
  50.         {
  51.             do
  52.             {
  53.                 System.out.printf("Examen %d (op 20): ", index+1);
  54.                 array[index] = s.nextInt();
  55.             }
  56.             while(array[index] < 0 || array[index] > 20);
  57.         }
  58.     }
  59.    
  60.     public static void berekenPercentage(int[][] examen, int[] percentages)
  61.     {      
  62.         for(int index = 0; index < examen.length; index++)
  63.         {
  64.             int totaal = 0;
  65.             int percentage;
  66.             for(int index2 = 0; index2 < examen[index].length; index2++)
  67.             {
  68.                 totaal += examen[index][index2];
  69.             }
  70.             percentage = (totaal*100/(examen[index].length*20));
  71.             percentages[index] = percentage;
  72.         }
  73.     }
  74.    
  75.     private static String maakUitvoer(int[][] examen, int[] percentages)
  76.     {
  77.         String s = "";
  78.        
  79.         for(int index = 0; index < examen.length; index++)
  80.         {
  81.             s += String.format("Student %d", index + 1);
  82.             int controle = 0;
  83.            
  84.             for(int index2 = 0; index2 < examen[index].length; index2++)
  85.             {
  86.                 if(examen[index][index2] < 10)
  87.                     controle++;
  88.                
  89.                 s += String.format("%10d", examen[index][index2]);
  90.             }
  91.            
  92.             s += String.format("%npercentage : %d %s%n", percentages[index], (percentages[index] >= 60 && controle == 0) ? "Geslaagd" : "Niet geslaagd");
  93.         }
  94.        
  95.         return s;
  96.     }
  97.    
  98.     public static double berekenGemiddeldPercentage(int[] percentages)
  99.     {
  100.        int totaal = 0;
  101.        double gemiddelde;
  102.        
  103.        for(int index = 0; index < percentages.length; index++)
  104.        {
  105.            totaal += percentages[index];
  106.        }
  107.        
  108.        gemiddelde = totaal/percentages.length;
  109.        
  110.        return gemiddelde;
  111.     }
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement