Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.Talar;
- import java.io.*;
- import java.util.*;
- public class Main {
- public static void main(String[] args) throws FileNotFoundException{
- char[] odpowiedzi = {'A','B','X','X','X'};
- Testy kolokwium = new Testy(5,5);
- kolokwium.wypiszDane(1);
- System.out.println("\nWynik: " + kolokwium.obliczWynik(1,odpowiedzi));
- System.out.println("Zaliczenie: " + kolokwium.zaliczonyTest(1,odpowiedzi));
- }
- }
- ---------------------------------------------------------
- ---------------------------------------------------------
- Plik: Testy.java
- ---------------------------------------------------------
- ---------------------------------------------------------
- package com.Talar;
- public class Testy {
- private char[][] testy;
- public Testy(int iloscTestow, int iloscPytan){
- testy = new char[iloscTestow][iloscPytan];
- for(int i = 0; i < iloscTestow; i++){
- for(int j = 0; j < iloscPytan; j++){
- testy[i][j] = 'X';
- }
- }
- }
- public float obliczWynik(int nrTestu, char[] odpowiedzi){
- int poprawne = 0;
- float wynik;
- for(int i = 0; i < testy[nrTestu].length; i++){
- if(testy[nrTestu][i] == odpowiedzi[i]) poprawne++;
- }
- wynik = (poprawne * 100 / testy[nrTestu].length);
- return wynik;
- }
- public boolean zaliczonyTest(int nrTestu, char[] odpowiedzi){
- boolean result = false;
- if(obliczWynik(nrTestu, odpowiedzi)>50) result = true;
- return result;
- }
- public void wypiszOdpowiedz(int nrTestu, int nrPyt, char odp){
- System.out.println("Twoja odpowiedź: " + odp);
- try{
- System.out.println("Odpowiedź dla " + nrTestu + "/" + nrPyt + ": " +
- testy[nrTestu][nrPyt]);
- }catch(ArrayIndexOutOfBoundsException e) { System.out.println("Nieprawidłowy numer testu/pytania"); }
- }
- public void wypiszDane(int nrTestu){
- try{
- System.out.println("Numer testu: " + nrTestu);
- for(int i = 0; i < testy[nrTestu].length; i++){
- System.out.print(testy[nrTestu][i] + "; ");
- }
- }catch(ArrayIndexOutOfBoundsException e) { System.out.println("Nieprawidłowy numer testu/pytania"); }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement