Limited access

Upgrade to access all content for this subject

Consider the following classes.

public class Movie
{
    private String movieRating;

    // other instance variables and methods not shown

    public String getRating()
    {
         // Returns the rating of the movie. implementation not shown
    }
}

public class Kiosk
{
    ArrayList<Movie> movies = new ArrayList<Movie>();

    // Create a method that accepts a rating and
    // returns all the movies with that rating.
    public ArrayList<Movie> findMoviesByRating(String rating)
    {
         ArrayList<Movie> moviesByRating = new ArrayList<Movie>();
         for (int i=0; i<movies.size(); i++)
         {
             // insert code here
         }
         return moviesByRating;
    }
}

Which section of code could replace // insert code here to complete the method?

A
if (movies.get(i).getRating().equals(rating))
{
     moviesByRating.add(movies.get(i));
}
B
if (movies.getRating().equals(rating))
{
     moviesByRating.add(movies);
}
C
if (movies.get(i).movieRating.equals(rating))
{
     moviesByRating.add(movieRating);
}
D
if (movies.get(i).movieRating.equals(rating))
{
     moviesByRating.add(movies.get(i));
}
E
if (movies.getRating().equals(rating))
{
     moviesByRating.add(movies.get(i));
}
Select an assignment template