41.0k views
2 votes
Tracy has a file that contains a list of actors and the movies in which they acted. She wants to know the top 3 ranked actors from her list whom have acted/appeared in the most movies. ACTOR_NAMEMOVIE_NAME Leonardo DiCaprioThe Revenant Christian BaleVice Morgan FreemanShawshank Redemption Leonardo DiCaprioThe Great Gatsby Christian BaleAmerican Psycho Morgan FreemanThe Dark Knight Christian BaleThe Dark Knight Samuel L. JacksonPulp Fiction Question: Write code in Java/Scala/Python to display the top 3 ranked actors appearing in the most movies based on the count of movies in which they have acted. If there are less than 3 actors in her list, display all of them. Consider all scenarios - such as, if two actors have acted in the same number of movies, they will have the same rank.

1 Answer

3 votes

Answer:

{

private String name;

private String review;

/** Constructs a ProductReview object and initializes the instance variables. */

public ProductReview(String pName, String pReview)

{

name = pName;

review = pReview;

}

/** Returns the name of the product. */

public String getName()

{ return name; }

/** Returns the review of the product. */

public String getReview()

{ return review; }

}

The ReviewCollector class, shown below, is used to represent a collection of reviews to be analyzed.

public class ReviewCollector

{

private ArrayList<ProductReview> reviewList;

private ArrayList<String> productList;

/** Constructs a ReviewCollector object and initializes the instance variables. */

public ReviewCollector()

{

reviewList = new ArrayList<ProductReview>();

productList = new ArrayList<String>();

}

/** Adds a new review to the collection of reviews, as described in part (a). */

public void addReview(ProductReview prodReview)

{ /* to be implemented in part (a) */ }

/** Returns the number of good reviews for a given product name, as described in part (b). */

public int getNumGoodReviews(String prodName)

{ /* to be implemented in part (b) */ }

// There may be instance variables, constructors, and methods not shown.

}

User Vrtx
by
6.8k points