Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.19 KB | None | 0 0
  1. public static void main(String[] args) {
  2. // TODO code application logic here
  3. Pytanie[] X = new Pytanie[7];
  4. try{
  5. X[0] = new JednoPytanie("Jaki jest Twoj ulubiony kolor", "niebieski", "czerwony", "zielony", 0);
  6. X[1] = new JednoPytanie("Ile masz lat", "10", "20", "30", 1);
  7. X[2] = new PytanieZlozone(2);
  8. ((PytanieZlozone) X[2]).UstawPytanie(0, new JednoPytanie("Blargh","a","b","c",2));
  9. ((PytanieZlozone) X[2]).UstawPytanie(1, new JednoPytanie("Czy kwiatki sa kolorowe","TAK","NIE","NIE WIEM",2));
  10. } catch(ZlePytanie P){
  11. System.out.println("Nieprawidlowe parametry pytania");
  12. }
  13. int WYNIK = 0;
  14. for(int i =0; i<X.length; i++){
  15. if(X[i]!=null) WYNIK += X[i].Testuj();
  16. }
  17. System.out.println("Wynik: " + WYNIK);
  18. }
  19. import java.io.BufferedReader;
  20. import java.io.IOException;
  21. import java.io.InputStreamReader;
  22. public class JednoPytanie extends Pytanie {
  23. private String Tresc;
  24. private String[] Odpowiedzi = new String[3];
  25. private int Numer;
  26.  
  27. public int GetNumer(){return Numer;}
  28.  
  29. public final void Wyswietl()
  30. {
  31. System.out.println(Tresc + "?\n");
  32. for(int i = 0; i<3; i++){
  33. System.out.println((i+1) + ") " + Odpowiedzi[i]);
  34. }
  35. }
  36.  
  37. public final int Testuj(){
  38. this.Wyswietl();
  39. System.out.print("Wybor: ");
  40. BufferedReader WE = new BufferedReader(new InputStreamReader(System.in));
  41. String s;
  42. int wybor = -1;
  43. try{
  44. s = WE.readLine();
  45. wybor = Integer.parseInt(s);
  46. }
  47. catch(IOException e){
  48. System.out.println(e.toString());
  49. }
  50. wybor--;
  51. if(wybor==this.GetNumer()) return 1;
  52. else return 0;
  53. }
  54. public final int LiczbaPytan(){return 1;}
  55. public JednoPytanie(String Pytanie, String Odp1, String Odp2, String Odp3, int Numer) throws ZlePytanie{
  56. if( Pytanie == null ||
  57. Odp1 == null ||
  58. Odp2 == null ||
  59. Odp3 == null ||
  60. Numer < 0 ||
  61. Numer > 2) throw new ZlePytanie();
  62. Tresc = Pytanie;
  63. Odpowiedzi[0] = Odp1;
  64. Odpowiedzi[1] = Odp2;
  65. Odpowiedzi[2] = Odp3;
  66. this.Numer = Numer;
  67. }
  68. }
  69. public class PytanieZlozone extends Pytanie{
  70. JednoPytanie[] Lista;
  71. public PytanieZlozone(int Liczba){
  72. Lista = new JednoPytanie[Liczba];
  73. }
  74. public final void UstawPytanie(int Index, JednoPytanie P){
  75. Lista[Index] = P;
  76. }
  77. public final int LiczbaPytan(){
  78. int licznik = 0;
  79. for(int i = 0; i<Lista.length; i++){
  80. if(Lista[i]!=null) licznik++;
  81. }
  82. return licznik;
  83. }
  84. public final void Wyswietl(){
  85. for(int i = 0; i<Lista.length; i++){
  86. if(Lista[i]!=null) Lista[i].Wyswietl();
  87. }
  88. }
  89. public final int Testuj(){
  90. int WYNIK = 0;
  91. for(int i = 0; i<Lista.length; i++){
  92. if(Lista[i]!=null) WYNIK += Lista[i].Testuj();
  93. }
  94. return WYNIK;
  95. }
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement