Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A student plans to analyze product reviews found on a Web site by looking for keywords in posted reviews. TheProductReviewclass, shown below, is used to

A student plans to analyze product reviews found on a Web site by looking for keywords in posted reviews. TheProductReviewclass, shown below, is used to represent a single review. A product review consists of a product name and a review of that product.

public class ProductReview

{

private String name;

private String review;

/**Constructs aProductReviewobject 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; }

}

TheReviewCollectorclass, shown below, is used to represent a collection of reviews to be analyzed.

public class ReviewCollector

{

private ArrayList reviewList;

private ArrayList productList;

/**Constructs aReviewCollectorobject and initializes the instance variables.*/

public ReviewCollector()

{

reviewList = new ArrayList();

productList = new ArrayList();

}

/**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.

}

(a) Write theaddReviewmethod, which adds a single product review, represented by aProductReviewobject, to theReviewCollectorobject. TheaddReviewmethod does the following when it adds a product review.

  • TheProductReviewobject is added to thereviewListinstance variable.
  • The product name from theProductReviewobject is added to theproductListinstance variable if the product name is not already found inproductList.

Elements may be added toreviewListandproductListin any order.

Complete methodaddReview.

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

public void addReview(ProductReview prodReview)

(b) Write thegetNumGoodReviewsmethod, which returns the number ofgoodreviews for a given product name. A review is considered good if it contains the string"best"(all lowercase). If there are no reviews with a matching product name, the method returns0.Note that a review that contains"BEST"or"Best"is not considered a good review (since not all the letters of"best"are lowercase), but a review that contains"asbestos"is considered a good review (since all the letters of"best"are lowercase).

Complete methodgetNumGoodReviews.

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

public int getNumGoodReviews(String prodName)

Class information for this question

  • public class ProductReview
  • private String name
  • private String review
  • public ProductReview(String pName, String pReview)
  • public String getName()
  • public String getReview()
  • public class ReviewCollector
  • private ArrayList reviewList
  • private ArrayList productList
  • public ReviewCollector()
  • public void addReview(ProductReview prodReview)
  • public int getNumGoodReviews(String prodName)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Dental Assisting

Authors: Doni Bird, Debbie Robinson

13th Edition

978-0323624855, 0323624855

Students also viewed these Programming questions