Advertisement
Guest User

Untitled

a guest
Mar 24th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.15 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class Movie {
  4. private long id;
  5. private String title;
  6. private Date releaseDate;
  7. private HashSet<String> category;
  8. private Integer budget;
  9. private Rating rating;
  10.  
  11. public long getId() {
  12. return id;
  13. }
  14.  
  15. public String getTitle() {
  16. return title;
  17. }
  18.  
  19. public Date getReleaseDate() {
  20. return releaseDate;
  21. }
  22.  
  23. public HashSet<String> getCategory() {
  24. return category;
  25. }
  26.  
  27. public Integer getBudget() {
  28. if (budget == null)
  29. return budget;
  30. else
  31. return 0;
  32. }
  33.  
  34. public Integer getIncome() {
  35. if (income == null)
  36. return income;
  37. else
  38. return 0;
  39. }
  40.  
  41. private Integer income;
  42.  
  43. public double getProfit() {
  44. return income - budget;
  45. }
  46.  
  47. public static final HashSet<String> knownCategories = new HashSet<String>() {{ add("horror"); add("comedy"); add("scifi"); }};
  48.  
  49. private static ArrayList<Movie> movies = new ArrayList<Movie>();
  50.  
  51. public static ArrayList<Movie> findByCategory(String cat) {
  52. ArrayList<Movie> movies = new ArrayList<Movie>();
  53. for (Movie movie : Movie.movies) {
  54. if (movie.getCategory().contains(cat))
  55. movies.add(movie);
  56. }
  57. return movies;
  58. }
  59.  
  60. public static ArrayList<Movie> findByRating(Rating rating) {
  61. ArrayList<Movie> movies = new ArrayList<Movie>();
  62. for (Movie movie : Movie.movies) {
  63. if (movie.rating == rating)
  64. movies.add(movie);
  65. }
  66. return movies;
  67. }
  68.  
  69. public Movie(long id, String title, Date releaseDate, HashSet<String> category, Integer budget, Rating rating, Integer income) {
  70. if (category.isEmpty()) {
  71. throw new IllegalArgumentException("categories cant be emppty");
  72. }
  73.  
  74.  
  75. this.id = id;
  76. this.title = title;
  77. this.releaseDate = releaseDate;
  78. this.category = new HashSet<String>();
  79. for (String cat : category) {
  80. if (knownCategories.contains(cat)) {
  81. this.category.add(cat);
  82. }
  83. }
  84. this.budget = budget;
  85. this.rating = rating;
  86. this.income = income;
  87.  
  88. movies.add(this);
  89. }
  90. }
  91.  
  92.  
  93. import java.util.Date;
  94. import java.util.HashSet;
  95.  
  96. public class Main {
  97.  
  98. public static void main(String[] args) {
  99.  
  100. System.out.println("Hello World!¬");
  101. Movie dramat = new Movie(1, "smolensk", new Date(), new HashSet<String>(){{add("drama");}}, 100, Rating._7, 500);
  102. Movie dramat2 = new Movie(1, "smolensk 2", new Date(), new HashSet<String>(){{add("drama"); add("horror");}}, 500, Rating._12, 500);
  103. Movie horror = new Movie(1, "maczeta", new Date(), new HashSet<String>(){{add("horror");}}, 500, Rating.AL, 500);
  104.  
  105. System.out.println(Movie.findByCategory("horror"));
  106. System.out.println(Movie.findByCategory("drama"));
  107. System.out.println(Movie.findByRating(Rating._7));
  108. System.out.println(dramat.getProfit());
  109. }
  110. }
  111.  
  112.  
  113. public enum Rating {
  114. AL, _7, _12, _15, _21
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement