Write a console program that puts Movie objects into a SortedList. The movies are sorted by their year of release. Movies contain actors of type Person which are sorted alphabetically by their last name.
🍿 Welcome to the movie database! 🎬 Title: Forrest Gump, Year: 1994, Genre: Drama Lead Actors: - Tom Hanks - Robin Wright Title: The Matrix, Year: 1999, Genre: Science Fiction Lead Actors: - Laurence Fishburne - Carrie-Anne Moss - Keanu Reeves Title: Interstellar, Year: 2014, Genre: Science Fiction Lead Actors: - Michael Caine - Anne Hathaway - Matthew McConaugheyConsider this class diagram:
You can use this method to create movies:
private static SortedListgetMovies() { SortedList movies = new SortedList<>(); Person[] actors1 = {new Person("Keanu", "Reeves"), new Person("Laurence", "Fishburne"), new Person("Carrie-Anne", "Moss")}; Movie m1 = new Movie("The Matrix", 1999, new SortedList<>(actors1), "Science Fiction"); movies.add(m1); Person[] actors2 = {new Person("Tom", "Hanks"), new Person("Robin", "Wright")}; Movie m2 = new Movie("Forrest Gump", 1994, new SortedList<>(actors2), "Drama"); movies.add(m2); Person[] actors3 = {new Person("Matthew", "McConaughey"), new Person("Anne", "Hathaway"), new Person("Michael", "Caine")}; Movie m3 = new Movie("Interstellar", 2014, new SortedList<>(actors3), "Science Fiction"); movies.add(m3); return movies; }
Method add in SortedList puts an element at the correct position based on the element's compare method (the element is Sortable).