gitweb on Svarog

projekti pod git sistemom za održavanje verzija -- projects under the git version control system
Skup, primer koriscenja sa sopstevnom klasom u kojoj je definisan metod equals
authorDoni Pracner <quinnuendo@gmail.com>
Wed, 6 May 2015 00:14:34 +0000 (02:14 +0200)
committerDoni Pracner <quinnuendo@gmail.com>
Wed, 6 May 2015 00:14:34 +0000 (02:14 +0200)
kodovi/skup/SkupoviStudenata.java [new file with mode: 0644]

diff --git a/kodovi/skup/SkupoviStudenata.java b/kodovi/skup/SkupoviStudenata.java
new file mode 100644 (file)
index 0000000..3df70e8
--- /dev/null
@@ -0,0 +1,79 @@
+public class SkupoviStudenata {
+
+       public static Skup<PorediviStudent> ucitajStudente(String imefajla) {
+               Skup<PorediviStudent> rez = new Skup<>();
+
+               String prez, ime;
+               int god;
+               while (!Svetovid.in(imefajla).isEmpty()) {
+                       prez = Svetovid.in(imefajla).readString();
+                       ime = Svetovid.in(imefajla).readString();
+                       god = Svetovid.in(imefajla).readInt();
+                       PorediviStudent novi = new PorediviStudent(ime, prez, god);
+                       rez.ubaci(novi);
+               }
+               return rez;
+       }
+
+       public static void dodajStudente(Skup<PorediviStudent> rez, String imefajla) {
+               String prez, ime;
+               int god;
+               while (!Svetovid.in(imefajla).isEmpty()) {
+                       prez = Svetovid.in(imefajla).readString();
+                       ime = Svetovid.in(imefajla).readString();
+                       god = Svetovid.in(imefajla).readInt();
+                       PorediviStudent novi = new PorediviStudent(ime, prez, god);
+                       rez.ubaci(novi);
+               }
+       }
+
+       // dati su spiskovi studenata na predmetima
+       // naci one koji slusaju sve predmete
+       public static void ucitajSve() {
+               Skup<PorediviStudent> spa = ucitajStudente("spa.txt");
+               Skup<PorediviStudent> pj = ucitajStudente("pj.txt");
+               Skup<PorediviStudent> baze = ucitajStudente("baze.txt");
+
+               System.out.println(spa);
+               System.out.println(pj);
+               System.out.println(spa.presek(pj).presek(baze));
+       }
+
+       public static void main(String[] args) {
+               ucitajSve();
+
+       }
+
+}
+
+class PorediviStudent {
+       public String ime, prezime;
+       public int godina;
+
+       public PorediviStudent(String i, String p, int g) {
+               ime = i;
+               prezime = p;
+               godina = g;
+       }
+
+       public String toString() {
+               return ime + " " + prezime + " " + godina;
+       }
+
+       public boolean equals(Object o) {
+               // proverimo jel se poreidmo sa drugim PoredivimStudentom
+               if (o instanceof PorediviStudent) {
+                       PorediviStudent drugi = (PorediviStudent) o;
+                       if (drugi.ime != null && ime != null) {
+                               if (!drugi.ime.equals(ime))
+                                       return false;
+                       }
+                       if (drugi.prezime != null && prezime != null) {
+                               if (!drugi.prezime.equals(prezime))
+                                       return false;
+                       }
+                       return drugi.godina == godina;
+               }
+               return false;
+       }
+}
Svarog.pmf.uns.ac.rs/gitweb maintanance Doni Pracner