Limited access

Upgrade to access all content for this subject

Consider the following classes.

public class MovieKiosk 
{
    int kioskNum;
    ArrayList<Movie> movies = new ArrayList<Movie> ();

    public MovieKiosk(int kiosk, ArrayList<Movie> movieList)
    {
        kioskNum = kiosk;
        movies = movieList;
    }

    public int getKioskNum()
    {
        return kioskNum;
    }

    public ArrayList<Movie> getMovies()
    {
        return movies;
    }

    // other data and methods not shown    
}

public class Movie
{
    public String getName()
    {
        // returns the title of the movie
    }

    // other data, constructors and methods not shown    
}

A company keeps track of all their movie kiosks in an array list. Each movie kiosk contains an arrayList of movies that are in the kiosk machine.

Consider the following method.

public static ArrayList<Integer> findKiosks(ArrayList<MovieKiosk> kiosks, String title)
{
    // missing code
}

Which of the following could be used to replace // missing code so that this method will search for a movie title and return an array list of the kiosk numbers of the kiosks that have the movie?

A
for (int i=0; i<kiosks.size(); i++)
{
    for (Movie m : kiosks)
    {
        if (m.getName().equals(title))
            return kiosks.get(i).getKioskNum();
    }
}
return null;
B
ArrayList<Integer> kioskNums = new ArrayList<Integer>();
for (int i=0; i<kiosks.size(); i++)
{
    for (Movie m : kiosks)
    {
        if (m.getName().equals(title))
            kioskNums.add(kiosks.get(i).getKioskNum());
    }
}
return kioskNums;
C
ArrayList<Integer> kioskNums = new ArrayList<Integer>();
for (int i=0; i<kiosks.size(); i++)
{
    for (int j=0; j<kiosks.get(j).getMovies().size(); j++)
    {
        if (kiosks.get(j).getName().equals(title))
             kioskNums.add(kiosks.get(j).getKioskNum());
    }
}
return kioskNums;
D
ArrayList<Integer> kioskNums = new ArrayList<Integer>();
for (Movie m : kiosks.getMovies())
{
    if (m.getName().equals(title))
        kioskNums.add(kiosks.getKioskNum());
}
return kioskNums;
E
ArrayList<Integer> kioskNums = new ArrayList<Integer>();
for (int i=0; i<kiosks.size(); i++)
{
    for (Movie m : kiosks.get(i).getMovies())
    {
        if (m.getName().equals(title))
            kioskNums.add(kiosks.get(i).getKioskNum());
    }
}
return kioskNums;
Select an assignment template