Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void main(String[] args) {
- // TODO code application logic here
- Pytanie[] X = new Pytanie[7];
- try{
- X[0] = new JednoPytanie("Jaki jest Twoj ulubiony kolor", "niebieski", "czerwony", "zielony", 0);
- X[1] = new JednoPytanie("Ile masz lat", "10", "20", "30", 1);
- X[2] = new PytanieZlozone(2);
- ((PytanieZlozone) X[2]).UstawPytanie(0, new JednoPytanie("Blargh","a","b","c",2));
- ((PytanieZlozone) X[2]).UstawPytanie(1, new JednoPytanie("Czy kwiatki sa kolorowe","TAK","NIE","NIE WIEM",2));
- } catch(ZlePytanie P){
- System.out.println("Nieprawidlowe parametry pytania");
- }
- int WYNIK = 0;
- for(int i =0; i<X.length; i++){
- if(X[i]!=null) WYNIK += X[i].Testuj();
- }
- System.out.println("Wynik: " + WYNIK);
- }
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- public class JednoPytanie extends Pytanie {
- private String Tresc;
- private String[] Odpowiedzi = new String[3];
- private int Numer;
- public int GetNumer(){return Numer;}
- public final void Wyswietl()
- {
- System.out.println(Tresc + "?\n");
- for(int i = 0; i<3; i++){
- System.out.println((i+1) + ") " + Odpowiedzi[i]);
- }
- }
- public final int Testuj(){
- this.Wyswietl();
- System.out.print("Wybor: ");
- BufferedReader WE = new BufferedReader(new InputStreamReader(System.in));
- String s;
- int wybor = -1;
- try{
- s = WE.readLine();
- wybor = Integer.parseInt(s);
- }
- catch(IOException e){
- System.out.println(e.toString());
- }
- wybor--;
- if(wybor==this.GetNumer()) return 1;
- else return 0;
- }
- public final int LiczbaPytan(){return 1;}
- public JednoPytanie(String Pytanie, String Odp1, String Odp2, String Odp3, int Numer) throws ZlePytanie{
- if( Pytanie == null ||
- Odp1 == null ||
- Odp2 == null ||
- Odp3 == null ||
- Numer < 0 ||
- Numer > 2) throw new ZlePytanie();
- Tresc = Pytanie;
- Odpowiedzi[0] = Odp1;
- Odpowiedzi[1] = Odp2;
- Odpowiedzi[2] = Odp3;
- this.Numer = Numer;
- }
- }
- public class PytanieZlozone extends Pytanie{
- JednoPytanie[] Lista;
- public PytanieZlozone(int Liczba){
- Lista = new JednoPytanie[Liczba];
- }
- public final void UstawPytanie(int Index, JednoPytanie P){
- Lista[Index] = P;
- }
- public final int LiczbaPytan(){
- int licznik = 0;
- for(int i = 0; i<Lista.length; i++){
- if(Lista[i]!=null) licznik++;
- }
- return licznik;
- }
- public final void Wyswietl(){
- for(int i = 0; i<Lista.length; i++){
- if(Lista[i]!=null) Lista[i].Wyswietl();
- }
- }
- public final int Testuj(){
- int WYNIK = 0;
- for(int i = 0; i<Lista.length; i++){
- if(Lista[i]!=null) WYNIK += Lista[i].Testuj();
- }
- return WYNIK;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement