fork download
  1.  
  2. import java.io.PrintWriter;
  3. import java.util.SortedSet;
  4. import java.util.TreeSet;
  5.  
  6. class Film implements Comparable {
  7.  
  8. private String tyt;
  9. private String rez;
  10. private double c;
  11. private String gat;
  12.  
  13. public Film(String tyt, String rez, double c, String gat) {
  14. this.tyt = tyt;
  15. this.rez = rez;
  16. this.c = c;
  17. this.gat = gat;
  18. }
  19.  
  20. @Override
  21. public String toString() {
  22. return "Film{" + "tyt=" + tyt + ", rez=" + rez + ", c=" + c + ", gat=" + gat + '}';
  23. }
  24.  
  25. public int compareTo(Object that) {
  26. if (that instanceof Film) {
  27. return tyt.compareTo(((Film)that).tyt);
  28. } else {
  29. return 1;
  30. }
  31. }
  32. }
  33.  
  34. class MagazynFilmow {
  35.  
  36. SortedSet<Film> filmy;
  37.  
  38. MagazynFilmow() {
  39. filmy = new TreeSet<Film>();
  40. }
  41.  
  42. void nowyFilm(String tyt, String rez, double c, String gat) {
  43. filmy.add(new Film(tyt, rez, c, gat));
  44. }
  45. }
  46.  
  47. public class Main {
  48.  
  49. public static void main(String[] args) {
  50. MagazynFilmow magazyn = new MagazynFilmow();
  51. magazyn.nowyFilm("Incepcja", "Jakistam", 19.99, "Akcji");
  52. magazyn.nowyFilm("Przykladowy1", "Przykladowy1", 20.99, "Komedia");
  53. String test_tytul = "Przykladowy2";
  54. String test_rezyser = "Przykadowy2";
  55. double test_cena = 19.99;
  56. String test_gatunek = "dramat";
  57. magazyn.nowyFilm(test_tytul, test_rezyser, test_cena, test_gatunek);
  58.  
  59. PrintWriter wyj = new PrintWriter(System.out);
  60. for (Film p : magazyn.filmy) {
  61. wyj.println(p.toString());
  62. wyj.flush();
  63. }
  64. }
  65. }
  66.  
Success #stdin #stdout 0.05s 213440KB
stdin
Standard input is empty
stdout
Film{tyt=Incepcja, rez=Jakistam, c=19.99, gat=Akcji}
Film{tyt=Przykladowy1, rez=Przykladowy1, c=20.99, gat=Komedia}
Film{tyt=Przykladowy2, rez=Przykadowy2, c=19.99, gat=dramat}