Answer:
Check the explanation
Explanation:
ProductReview.java
public class ProductReview {
private String name;
private String review;
public ProductReview(String name, String review) {
super();
this.name = name;
this.review = review;
}
public String getName() {
return name;
}
public String getReview() {
return review;
}
}
ReviewCollector.java
import java.util.ArrayList;
public class ReviewCollector {
private ArrayList<ProductReview> reviewList;
private ArrayList<String> productList;
public ReviewCollector(ArrayList<ProductReview> reviewList, ArrayList<String> productList) {
super();
this.reviewList = reviewList;
this.productList = productList;
}
public void addReview(ProductReview prodReview) {
this.reviewList.add(prodReview);
}
public int getNumGoodReviews(String prodName) {
int count = 0;
ArrayList<ProductReview> set = new ArrayList<>();
for (int i = 0; i < reviewList.size(); i++) {
if (reviewList.get(i).getName().compareToIgnoreCase(prodName) == 0) {
set.add(reviewList.get(i));
}
}
if(set.size()==0)
return count;
for (int i = 0; i < set.size(); i++) {
if (set.get(i).getReview().contains("best")) {
count++;
}
}
return count;
}
}