Advertisement
Guest User

Untitled

a guest
Nov 25th, 2014
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.92 KB | None | 0 0
  1. package laboratoria5;
  2. import java.util.*;
  3.  
  4. public class Student {
  5. int nr;
  6. String imie;
  7. ArrayList<Integer> oceny;
  8. public boolean equals(Object o) {
  9. if (!(o instanceof Student)) return false; //instanceof: jezeli o pasuje do student
  10. Student s = (Student)o; //rzutujemy obiekt o na student i przypisujemy do studenta s
  11. return (s.nr==nr); //sprawdza czy podany numer jest zgodny z obecnie sprawdzanym nr studenta
  12. }
  13. Student(int nr, String imie) //konstruktor student
  14. {
  15. this.nr=nr;
  16. this.imie=imie;
  17. this.oceny= new ArrayList<Integer>();
  18. }
  19. public String toString()
  20. {
  21. return nr+" "+imie+"\t"+oceny;
  22. }
  23.  
  24. }
  25. class WykazS
  26. {
  27. ArrayList<Student> wykaz;
  28. WykazS()
  29. {
  30. this.wykaz= new ArrayList<Student>();
  31. }
  32.  
  33. void wstawStudenta(int nr, String imie)
  34. {
  35. //wstawia studenta z pusta lista ocen
  36. wykaz.add(new Student(nr, imie));
  37. }
  38.  
  39. void wstawOcene(int nr, int ocena)
  40. {
  41. //dostawia ocene studentowi o podanym numerze indeksu
  42. int album = wykaz.indexOf(new Student(nr,"")); //indexof: szukanie pola w liscie i odwoluje sie do
  43. //equals
  44. wykaz.get(album).oceny.add(ocena);
  45. }
  46.  
  47. void wypisz(int nr)
  48. {
  49. int album = wykaz.indexOf(new Student(nr,""));
  50. System.out.println(wykaz.get(album));
  51. }
  52.  
  53. void wypisz()
  54. {
  55. for (int j=0; j<wykaz.size(); j++){ // petla po liscie
  56. System.out.println(wykaz.get(j));
  57. }
  58. }
  59.  
  60.  
  61. void sortujA()
  62. {
  63. Collections.sort(wykaz, new CompareS());
  64. }
  65.  
  66. void sortujS()
  67. {
  68. }
  69.  
  70. }
  71. class testStudent{
  72. public static void main(String[] a)
  73. {
  74. // klasa testujaca klasy Student i WykazS
  75.  
  76.  
  77. WykazS ws = new WykazS();
  78.  
  79. ws.wstawStudenta(199200,"Kazik");
  80. ws.wstawStudenta(199201,"Kazik");
  81. ws.wstawStudenta(199204,"Nikodem");
  82. ws.wstawStudenta(199205,"Jan");
  83. ws.wstawStudenta(189557,"Wiesiek");
  84.  
  85. ws.wstawOcene(199200,5);
  86. ws.wstawOcene(199200,4);
  87. ws.wstawOcene(199200,3);
  88. ws.wstawOcene(199200,5);
  89. ws.wstawOcene(199200,2);
  90.  
  91. ws.wstawOcene(199201,5);
  92. ws.wstawOcene(199201,6);
  93.  
  94. ws.wstawOcene(199204,4);
  95. ws.wstawOcene(199204,5);
  96. ws.wstawOcene(199201,4);
  97.  
  98. ws.wstawOcene(199205,3);
  99. ws.wstawOcene(189557,5);
  100. /*
  101. ws.wypisz();
  102. ws.wypisz(199200);
  103. */
  104. ws.sortujA();
  105. ws.wypisz();
  106. }
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement