Write the addReview method, which adds a single product review, represented by a ProductReview object, to the ReviewCollector object. The addReview method does the following when it adds a product review. The ProductReview object is added to the reviewList instance variable. The product name from the ProductReview object is added to the productList instance variable if the product name is not already found in productList. Elements may be added to reviewList and productList in any order. Complete method addReview. /** Adds a new review to the collection of reviews, as described in part (a) */ public void addReview( ProductReview prodReview )

Respuesta :

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.

}

In this exercise we have to use the knowledge in computational language in C++ to write the following code:

We have the code can be found in the attached image.

So in an easier way we have that the code is

{

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) */ }

}

See more about C++ code at brainly.com/question/19705654

Ver imagen lhmarianateixeira