Advertisement
Talar97

[Zad 1] Testy

Jan 29th, 2018
377
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.32 KB | None | 0 0
  1. package com.Talar;
  2.  
  3. import java.io.*;
  4. import java.util.*;
  5.  
  6. public class Main {
  7.  
  8.     public static void main(String[] args) throws FileNotFoundException{
  9.         char[] odpowiedzi = {'A','B','X','X','X'};
  10.  
  11.         Testy kolokwium = new Testy(5,5);
  12.         kolokwium.wypiszDane(1);
  13.         System.out.println("\nWynik: " + kolokwium.obliczWynik(1,odpowiedzi));
  14.         System.out.println("Zaliczenie: " + kolokwium.zaliczonyTest(1,odpowiedzi));
  15.     }
  16. }
  17.  
  18.  
  19. ---------------------------------------------------------
  20. ---------------------------------------------------------
  21. Plik: Testy.java
  22. ---------------------------------------------------------
  23. ---------------------------------------------------------
  24.  
  25. package com.Talar;
  26.  
  27. public class Testy {
  28.     private char[][] testy;
  29.  
  30.     public Testy(int iloscTestow, int iloscPytan){
  31.         testy = new char[iloscTestow][iloscPytan];
  32.         for(int i = 0; i < iloscTestow; i++){
  33.             for(int j = 0; j < iloscPytan; j++){
  34.                 testy[i][j] = 'X';
  35.             }
  36.         }
  37.     }
  38.  
  39.     public float obliczWynik(int nrTestu, char[] odpowiedzi){
  40.         int poprawne = 0;
  41.         float wynik;
  42.  
  43.         for(int i = 0; i < testy[nrTestu].length; i++){
  44.             if(testy[nrTestu][i] == odpowiedzi[i]) poprawne++;
  45.         }
  46.         wynik = (poprawne * 100 / testy[nrTestu].length);
  47.         return wynik;
  48.     }
  49.  
  50.     public boolean zaliczonyTest(int nrTestu, char[] odpowiedzi){
  51.         boolean result = false;
  52.         if(obliczWynik(nrTestu, odpowiedzi)>50) result = true;
  53.         return result;
  54.     }
  55.  
  56.     public void wypiszOdpowiedz(int nrTestu, int nrPyt, char odp){
  57.         System.out.println("Twoja odpowiedź: " + odp);
  58.         try{
  59.             System.out.println("Odpowiedź dla " + nrTestu + "/" + nrPyt + ": " +
  60.                     testy[nrTestu][nrPyt]);
  61.         }catch(ArrayIndexOutOfBoundsException e) { System.out.println("Nieprawidłowy numer testu/pytania"); }
  62.     }
  63.  
  64.     public void wypiszDane(int nrTestu){
  65.         try{
  66.             System.out.println("Numer testu: " + nrTestu);
  67.             for(int i = 0; i < testy[nrTestu].length; i++){
  68.                 System.out.print(testy[nrTestu][i] + "; ");
  69.             }
  70.         }catch(ArrayIndexOutOfBoundsException e) { System.out.println("Nieprawidłowy numer testu/pytania"); }
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement