fork download
  1.  
  2. import java.io.PrintWriter;
  3. import java.util.SortedSet;
  4. import java.util.TreeSet;
  5.  
  6. class Film implements Comparable<Film> {
  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(Film that) {
  26. return tyt.compareTo(that.tyt);
  27. }
  28. }
  29.  
  30. class MagazynFilmow {
  31.  
  32. SortedSet<Film> filmy;
  33.  
  34. MagazynFilmow() {
  35. filmy = new TreeSet<Film>();
  36. }
  37.  
  38. void nowyFilm(String tyt, String rez, double c, String gat) {
  39. filmy.add(new Film(tyt, rez, c, gat));
  40. }
  41. }
  42.  
  43. public class Main {
  44.  
  45. public static void main(String[] args) {
  46. MagazynFilmow magazyn = new MagazynFilmow();
  47. magazyn.nowyFilm("Incepcja", "Jakistam", 19.99, "Akcji");
  48. magazyn.nowyFilm("Przykladowy1", "Przykladowy1", 20.99, "Komedia");
  49. String test_tytul = "Przykladowy2";
  50. String test_rezyser = "Przykadowy2";
  51. double test_cena = 19.99;
  52. String test_gatunek = "dramat";
  53. magazyn.nowyFilm(test_tytul, test_rezyser, test_cena, test_gatunek);
  54.  
  55. PrintWriter wyj = new PrintWriter(System.out);
  56. for (Film p : magazyn.filmy) {
  57. wyj.println(p.toString());
  58. wyj.flush();
  59. }
  60. }
  61. }
  62.  
Success #stdin #stdout 0.04s 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}