Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package laboratoria5;
- import java.util.*;
- public class Student {
- int nr;
- String imie;
- ArrayList<Integer> oceny;
- public boolean equals(Object o) {
- if (!(o instanceof Student)) return false; //instanceof: jezeli o pasuje do student
- Student s = (Student)o; //rzutujemy obiekt o na student i przypisujemy do studenta s
- return (s.nr==nr); //sprawdza czy podany numer jest zgodny z obecnie sprawdzanym nr studenta
- }
- Student(int nr, String imie) //konstruktor student
- {
- this.nr=nr;
- this.imie=imie;
- this.oceny= new ArrayList<Integer>();
- }
- public String toString()
- {
- return nr+" "+imie+"\t"+oceny;
- }
- }
- class WykazS
- {
- ArrayList<Student> wykaz;
- WykazS()
- {
- this.wykaz= new ArrayList<Student>();
- }
- void wstawStudenta(int nr, String imie)
- {
- //wstawia studenta z pusta lista ocen
- wykaz.add(new Student(nr, imie));
- }
- void wstawOcene(int nr, int ocena)
- {
- //dostawia ocene studentowi o podanym numerze indeksu
- int album = wykaz.indexOf(new Student(nr,"")); //indexof: szukanie pola w liscie i odwoluje sie do
- //equals
- wykaz.get(album).oceny.add(ocena);
- }
- void wypisz(int nr)
- {
- int album = wykaz.indexOf(new Student(nr,""));
- System.out.println(wykaz.get(album));
- }
- void wypisz()
- {
- for (int j=0; j<wykaz.size(); j++){ // petla po liscie
- System.out.println(wykaz.get(j));
- }
- }
- void sortujA()
- {
- Collections.sort(wykaz, new CompareS());
- }
- void sortujS()
- {
- }
- }
- class testStudent{
- public static void main(String[] a)
- {
- // klasa testujaca klasy Student i WykazS
- WykazS ws = new WykazS();
- ws.wstawStudenta(199200,"Kazik");
- ws.wstawStudenta(199201,"Kazik");
- ws.wstawStudenta(199204,"Nikodem");
- ws.wstawStudenta(199205,"Jan");
- ws.wstawStudenta(189557,"Wiesiek");
- ws.wstawOcene(199200,5);
- ws.wstawOcene(199200,4);
- ws.wstawOcene(199200,3);
- ws.wstawOcene(199200,5);
- ws.wstawOcene(199200,2);
- ws.wstawOcene(199201,5);
- ws.wstawOcene(199201,6);
- ws.wstawOcene(199204,4);
- ws.wstawOcene(199204,5);
- ws.wstawOcene(199201,4);
- ws.wstawOcene(199205,3);
- ws.wstawOcene(189557,5);
- /*
- ws.wypisz();
- ws.wypisz(199200);
- */
- ws.sortujA();
- ws.wypisz();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement