Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Movie {
- private long id;
- private String title;
- private Date releaseDate;
- private HashSet<String> category;
- private Integer budget;
- private Rating rating;
- public long getId() {
- return id;
- }
- public String getTitle() {
- return title;
- }
- public Date getReleaseDate() {
- return releaseDate;
- }
- public HashSet<String> getCategory() {
- return category;
- }
- public Integer getBudget() {
- if (budget == null)
- return budget;
- else
- return 0;
- }
- public Integer getIncome() {
- if (income == null)
- return income;
- else
- return 0;
- }
- private Integer income;
- public double getProfit() {
- return income - budget;
- }
- public static final HashSet<String> knownCategories = new HashSet<String>() {{ add("horror"); add("comedy"); add("scifi"); }};
- private static ArrayList<Movie> movies = new ArrayList<Movie>();
- public static ArrayList<Movie> findByCategory(String cat) {
- ArrayList<Movie> movies = new ArrayList<Movie>();
- for (Movie movie : Movie.movies) {
- if (movie.getCategory().contains(cat))
- movies.add(movie);
- }
- return movies;
- }
- public static ArrayList<Movie> findByRating(Rating rating) {
- ArrayList<Movie> movies = new ArrayList<Movie>();
- for (Movie movie : Movie.movies) {
- if (movie.rating == rating)
- movies.add(movie);
- }
- return movies;
- }
- public Movie(long id, String title, Date releaseDate, HashSet<String> category, Integer budget, Rating rating, Integer income) {
- if (category.isEmpty()) {
- throw new IllegalArgumentException("categories cant be emppty");
- }
- this.id = id;
- this.title = title;
- this.releaseDate = releaseDate;
- this.category = new HashSet<String>();
- for (String cat : category) {
- if (knownCategories.contains(cat)) {
- this.category.add(cat);
- }
- }
- this.budget = budget;
- this.rating = rating;
- this.income = income;
- movies.add(this);
- }
- }
- import java.util.Date;
- import java.util.HashSet;
- public class Main {
- public static void main(String[] args) {
- System.out.println("Hello World!¬");
- Movie dramat = new Movie(1, "smolensk", new Date(), new HashSet<String>(){{add("drama");}}, 100, Rating._7, 500);
- Movie dramat2 = new Movie(1, "smolensk 2", new Date(), new HashSet<String>(){{add("drama"); add("horror");}}, 500, Rating._12, 500);
- Movie horror = new Movie(1, "maczeta", new Date(), new HashSet<String>(){{add("horror");}}, 500, Rating.AL, 500);
- System.out.println(Movie.findByCategory("horror"));
- System.out.println(Movie.findByCategory("drama"));
- System.out.println(Movie.findByRating(Rating._7));
- System.out.println(dramat.getProfit());
- }
- }
- public enum Rating {
- AL, _7, _12, _15, _21
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement