From: Doni Pracner Date: Sun, 15 Mar 2015 19:41:09 +0000 (+0100) Subject: Dodat primer za rad sa spiskom studenata X-Git-Url: https://svarog.pmf.uns.ac.rs/gitweb/?a=commitdiff_plain;h=cd39e2f00c3e47632479f7da5a90a5d1a7e4c6d9;p=spa1-materijali.git Dodat primer za rad sa spiskom studenata --- diff --git a/kodovi/klase/Studenti.java b/kodovi/klase/Studenti.java new file mode 100644 index 0000000..19cbfb6 --- /dev/null +++ b/kodovi/klase/Studenti.java @@ -0,0 +1,151 @@ +public class Studenti { + + // promenljiva koja ce se videti u glavnom programu mora biti static + static SpisakStudenata spisak = null; + + public static void main(String[] args) { + String imeF = Svetovid.in.readString("Unesite ime fajla:"); + spisak = new SpisakStudenata(); + spisak.ucitajStudente(imeF); + + Svetovid.out.println("Studenti iz fajla:"); + spisak.ispisiStudenteNaEkran(); + Svetovid.out.println(); + + Svetovid.out.println("Unos novog studenta:"); + String ime = Svetovid.in.readString("Unesite ime studenta:"); + String prez = Svetovid.in.readString("Unesite prezime studenta:"); + int god = Svetovid.in.readInt("Unesite godinu rodjenja studenta:"); + + spisak.dodajStudenta(ime, prez, god); + + Svetovid.out.println(); + + god = Svetovid.in + .readInt("Unesite godinu na osnovu koje zelite izlistavanje:"); + Svetovid.out.println("Spisak studenata rodjenih " + god + ". godine: "); + spisak.ispisiStudenteSaGodinom(god); + Svetovid.out.println(); + + Svetovid.out.println("Rodjenih pre " + god + ". godine ima: " + + spisak.prebrojStudentePreGodine(god)); + Svetovid.out.println(); + + String imeF2 = Svetovid.in.readString("Unesite ime fajla za ispis:"); + spisak.ispisiStudenteUFajl(imeF2); + + } + +} + +class Student { + public String ime, prezime; + public int godina; + + public Student(String i, String p, int g) { + ime = i; + prezime = p; + godina = g; + } + + public String toString() { + return ime + " " + prezime + " " + godina; + } +} + +class SpisakStudenata { + // konstante na nivou klase oznacavamo sa final static + final static int MAX_BR_STUDENATA = 100; + + public Student[] spisakStudenata; + public int brojSt; + + /** Kreira nov prazan spisak studenata */ + public SpisakStudenata() { + spisakStudenata = new Student[MAX_BR_STUDENATA]; + brojSt = 0; + } + + /** Ucitava studente iz datog fajla u ovaj spisak studenata */ + public void ucitajStudente(String f) { + String i, p; + int god; + + while (!Svetovid.in(f).isEmpty() && brojSt < MAX_BR_STUDENATA) { + p = Svetovid.in(f).readString(); + i = Svetovid.in(f).readString(); + god = Svetovid.in(f).readInt(); + dodajStudenta(i, p, god); + } + + if (!Svetovid.in(f).isEmpty()) { + Svetovid.out.println("Previse studenata u fajlu! Ucitano prvih " + + MAX_BR_STUDENATA); + } + + Svetovid.in(f).close(); + } + + /** Dodaje studenta sa datim podacima u ovaj spisak studenata */ + public void dodajStudenta(String i, String p, int g) { + // proverimo da li ima mesta + if (brojSt < MAX_BR_STUDENATA) { + spisakStudenata[brojSt] = new Student(i, p, g); + brojSt++; + } else { + Svetovid.out.println("Previse studenata u nizu!"); + } + } + + public void ispisiStudenteUFajl(String f) { + for (int i = 0; i < brojSt; i++) { + Svetovid.out(f).print(spisakStudenata[i].prezime); + Svetovid.out(f).print(" "); + Svetovid.out(f).print(spisakStudenata[i].ime); + Svetovid.out(f).print(" "); + Svetovid.out(f).println(spisakStudenata[i].godina); + } + Svetovid.out(f).close(); + } + + public void ispisiStudenteNaEkran() { + for (int i = 0; i < brojSt; i++) { + Svetovid.out.print(spisakStudenata[i].prezime); + Svetovid.out.print(" "); + Svetovid.out.print(spisakStudenata[i].ime); + Svetovid.out.print(" "); + Svetovid.out.println(spisakStudenata[i].godina); + } + } + + public void ispisiStudenteSaGodinom(int god) { + for (int i = 0; i < brojSt; i++) { + if (spisakStudenata[i].godina == god) { + Svetovid.out.println(spisakStudenata[i]); + } + } + } + + public int prebrojStudentePreGodine(int god) { + int br = 0; + for (int i = 0; i < brojSt; i++) { + if (spisakStudenata[i].godina < god) { + br++; + } + } + return br; + } + + // vraca String koji predstavlja ovaj niz studenata + public String toString() { + String st = "Studenti ["; + if (brojSt > 0) { + st += spisakStudenata[0]; + } + for (int i = 1; i < brojSt; i++) { + st += ", " + spisakStudenata[i]; + } + st += "]"; + return st; + } +} diff --git a/kodovi/klase/stud10.txt b/kodovi/klase/stud10.txt new file mode 100644 index 0000000..e06ccf4 --- /dev/null +++ b/kodovi/klase/stud10.txt @@ -0,0 +1,10 @@ +Bogorodichic Ema 1969 +Mrachic Milan 1988 +Basic Zeljko 1953 +Bosnic Milena 1953 +Tanaskovic Kristina 1988 +Peulic Kristijan 1972 +Minchic Suzana 1988 +Zurovac Andrijana 1963 +Dugalic Mirjana 1957 +Vidovic Jelena 1970 \ No newline at end of file diff --git a/kodovi/klase/stud100.txt b/kodovi/klase/stud100.txt new file mode 100644 index 0000000..2bb3513 --- /dev/null +++ b/kodovi/klase/stud100.txt @@ -0,0 +1,100 @@ +Dobrichic Marija 1967 +Hadzi-Tanchic Biljana 1955 +Saponjic Ivan 1955 +Demic Sinisa 1952 +Vujichic Boris 1961 +Arambasic Helena 1981 +Rakic Petra 1966 +Bukvic Tina 1987 +Brakochevic Tatjana 1989 +Jovic Vojin 1978 +Eremic Miljana 1965 +Glisic Filip 1955 +Amidzic Danijela 1974 +Babamiljic Maksim 1962 +Vasic Andrija 1972 +Bachic Duska 1963 +Antic Tatjana 1967 +Kalajdzic Bozidar 1973 +Ilijic Magdalena 1972 +Simanic Zoran 1957 +Popadic Vladan 1962 +Jovichic Vojislav 1964 +Aleksic Doroteja 1961 +Dangic Aleksandra 1962 +Abadzic Zlatka 1969 +Chaic Tanja 1963 +Bosiorchic Miljana 1955 +Chaic Dragan 1961 +Raletic Danilo 1953 +Grbovic Mahailo 1965 +Antic Matija 1986 +Budisic Slobodan 1952 +Trisic Stevan 1959 +Rosic Ljiljana 1980 +Minchic Predrag 1955 +Egeric Gordana 1971 +Vuchinic Alen 1962 +Bozichic Natalija 1979 +Maric Miroslav 1968 +Mileusnic Bogdan 1967 +Paunic Damir 1959 +Aljanchic Andrijana 1971 +Curdic Zlatko 1965 +Maletkovic Jelena 1971 +Bojic Slobodan 1955 +Radovic Danica 1982 +Kalabic Mladen 1973 +Remetic Masa 1963 +Budinic Zlatko 1955 +Gambelic Dunja 1987 +Blesic Marta 1955 +Dichic Jozef 1961 +Grubisic Mia 1975 +Mandic Dragana 1983 +Chavic Natalija 1973 +Bosiochic Gavrilo 1978 +Bunchic Nikolina 1980 +Bezanic Stasa 1964 +Mandic Jovana 1972 +Anic Miljana 1962 +Cyric Sanja 1969 +Katic Miroslav 1969 +Trninic Veljko 1967 +Kosutic Mina 1964 +Zrnic Filip 1969 +Genchic Nenad 1950 +Nikolesic Anastasija 1989 +Knezic Sergej 1952 +Jovanikic Mirko 1982 +Velikic Danijel 1986 +Djeric Elena 1962 +Radichic Martin 1978 +Besjedic Mila 1974 +Vujanic Miroslav 1978 +Cajic Vojin 1977 +Ilkic Danijela 1964 +Glintic Dragana 1967 +Misic Ivana 1961 +Zivanic Milan 1985 +Cmolic Mateja 1961 +Okolic Nina 1974 +Kvrgic Mia 1983 +Sikimic Jovan 1979 +Ardalic Sonja 1950 +Belchic Una 1973 +Ivanic Luka 1951 +Blesic Danijel 1975 +Milovac Tatjana 1982 +Ajduchic Anja 1955 +Santic Andrej 1969 +Arsic Vladan 1967 +Ojdanic Dejan 1962 +Brdaric Dragoslav 1956 +Gostojic Todor 1953 +Bosnic Uros 1980 +Biserchic Dunja 1962 +Glisic Anita 1953 +Paunic Goran 1962 +Bralusic Ivan 1981 +Blagovic Zeljko 1963 \ No newline at end of file diff --git a/kodovi/klase/stud50.txt b/kodovi/klase/stud50.txt new file mode 100644 index 0000000..e4da7a6 --- /dev/null +++ b/kodovi/klase/stud50.txt @@ -0,0 +1,50 @@ +Grubetic Kosta 1957 +Pesic Tanja 1965 +Toplichic Damir 1984 +Kacanski Anja 1958 +Dabic Marina 1955 +Gajic Dusanka 1973 +Jaglichic Zorana 1978 +Diskic Jozef 1970 +Vlajic Goran 1966 +Trivic Nenad 1951 +Vranic Rastko 1950 +Luzaic Jakov 1954 +Bjelovitic Marina 1950 +Spasic Marina 1975 +Besjedic Danilo 1960 +Bjelotomic Robert 1956 +Ivanic Milan 1984 +Panic Viktor 1958 +Kljajic Nenad 1987 +Kovacevic David 1957 +Knezic Danilo 1987 +Dolinic Jovan 1954 +Milovanovic Konstantin 1982 +Bajagic Zeljko 1964 +Abdulic Srdjan 1973 +Adamic Luka 1956 +Chaic Damir 1974 +Krsic Dragan 1978 +Jovetic Ema 1970 +Zlomislic Danijela 1965 +Draganic Monika 1981 +Vidovic Lav 1968 +Besedic Konstantin 1966 +Tovarisic Rastko 1974 +Boric Dobrosav 1983 +Pajic Danijela 1989 +Djurichic Bosko 1976 +Biljanic Jovan 1953 +Cvijetic Relja 1989 +Bastic Todor 1986 +Grbovic Darija 1975 +Bolachic Andreja 1968 +Gusic Hektor 1962 +Buljevic Andrej 1965 +Stanic Nikola 1969 +Sobajic Anja 1953 +Vasilic Maja 1962 +Vujisic Magdalena 1950 +Ekmechic Miroslav 1967 +Bozichic Natalija 1955 \ No newline at end of file