Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Filmovi zad SPA2:
- import java.util.Arrays;
- import java.util.Comparator;
- import java.util.Objects;
- import org.svetovid.io.SvetovidReader;
- class Film implements Comparable<Film>
- {
- public final int idf;
- public final String naziv;
- public final String reditelj;
- public Film(int idf,String naziv,String reditelj)
- {
- this.idf=idf;
- this.naziv=naziv;
- this.reditelj=reditelj;
- }
- public String toString()
- {
- return "ID filma: " + idf + "Naziv: " + "Reditelj:" + reditelj;
- }
- @Override
- public int compareTo(Film that)
- {
- int rezultat=Objects.compare(this.naziv, that.naziv, String.CASE_INSENSITIVE_ORDER);
- if(rezultat==0)
- {
- rezultat=this.idf-that.idf;
- }
- return rezultat;
- }
- }
- public class Filmovi
- {
- public static void main(String[] args)
- {
- String fajl=Svetovid.in.readLine("Unesite naziv filma");
- Film[] niz = ucitajFilmove(fajl);
- if (niz == null) {
- Svetovid.out.println("Dati fajl nije mogao da se procita! Proverite da li postoji.");
- return;
- }
- stampajNiz(niz);
- sortirajNiz(niz);
- }
- public static Film[] ucitajFilmove(String fajl)
- {
- if(!Svetovid.testIn(fajl))
- {
- return null;
- }
- SvetovidReader in=Svetovid.in(fajl);
- int br=in.readInt();
- Film[] rez=new Film[br];
- for (int i=0;i<br;i++)
- {
- int idf=in.readInt();
- String naziv=in.readLine();
- String reditelj=in.readLine();
- Film film =new Film(idf,naziv,reditelj);
- rez[i]=film;
- }
- Svetovid.closeIn(fajl);
- return rez;
- }
- public static void stampajNiz( Film[] niz)
- {
- for (Film a : niz)
- {
- Svetovid.out.printf(" (%4d) %20s %n", a.idf, a.naziv, a.reditelj);
- }
- }
- private static void sortirajNiz(Film[] niz)
- {
- Arrays.sort(niz);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement