Last active
September 1, 2022 18:42
-
-
Save inadarei/e60e061e291234043c2b6eb97a569bd9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
class MovieDashboard { | |
public static void main(String[] args) { | |
System.out.println("Getting movies..."); | |
MovieLister mv = new MovieLister(); | |
Movie[] toWatch = mv.moviesDirectedBy("Quentin Tarantino"); | |
System.out.println (Arrays.toString(toWatch)); | |
} | |
} | |
class MovieLister { | |
Finder finder = new Finder(); | |
public Movie[] moviesDirectedBy(String arg) { | |
List<Movie> allMovies = finder.findAll(); | |
for (Iterator it = allMovies.iterator(); it.hasNext();) { | |
Movie movie = (Movie) it.next(); | |
if (!movie.getDirector().equals(arg)) it.remove(); | |
} | |
return (Movie[]) allMovies.toArray(new Movie[allMovies.size()]); | |
} | |
} | |
class Movie { | |
private String director; | |
private String name; | |
public Movie(String name, String director) { | |
this.director = director; | |
this.name = name; | |
} | |
public String getDirector() { | |
return this.director; | |
} | |
public String toString() { | |
return this.name + " directed by " + this.director; | |
} | |
} | |
class Finder { | |
public List<Movie> findAll() { | |
ArrayList<Movie> movies = new ArrayList<Movie>(); | |
movies.add(new Movie("Pulp Fiction", "Quentin Tarantino")); | |
movies.add(new Movie("Inglorious Bastards", "Quentin Tarantino")); | |
movies.add(new Movie("Reservoid Dogs", "Quentin Tarantino")); | |
movies.add(new Movie("Kill Bill 1", "Quentin Tarantino")); | |
movies.add(new Movie("Kill Bill 2", "Quentin Tarantino")); | |
movies.add(new Movie("Taxi Driver", "Martin Scorsese")); | |
movies.add(new Movie("GoodFellas", "Martin Scorsese")); | |
movies.add(new Movie("The Irishman", "Martin Scorsese")); | |
return movies; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment