1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Irina-Kira [14]
2 years ago
11

Assume that the classes listed in the Java Quick Reference have been imported where appropriate. Unless otherwise noted in the q

uestion, assume that parameters in method calls are not null and that methods are called only when their preconditions are satisfied. In writing solutions for each question, you may use any of the accessible methods that are listed in classes defined in that question. Writing significant amounts of code that can be replaced by a call to one of these methods will not receive full credit.
A student plans to analyze product reviews found on a Web site by looking for keywords in posted reviews. The ProductReview class, 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 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 reviewList;
private ArrayList productList;
/** Constructs a ReviewCollector object 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 the addReview method, which adds a single product review, represented by a ProductReview object, to the ReviewCollector object. TheaddReview 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 inproductList.
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)
BoldItalicUnderlineBullet listNumbered list
0 / 10000 Word Limit

(b) Write the getNumGoodReviews method, which returns the number of good reviews 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 returns 0. 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 method getNumGoodReviews.

/** 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)
Computers and Technology
1 answer:
mash [69]2 years ago
4 0

Answer:

See explaination

Explanation:

import java.util.*;

class UserName{

ArrayList<String> possibleNames;

UserName(String firstName, String lastName){

if(this.isValidName(firstName) && this.isValidName(lastName)){

possibleNames = new ArrayList<String>();

for(int i=1;i<firstName.length()+1;i++){

possibleNames.add(lastName+firstName.substring(0,i));

}

}else{

System.out.println("firstName and lastName must contain letters only.");

}

}

public boolean isUsed(String name, String[] arr){

for(int i=0;i<arr.length;i++){

if(name.equals(arr[i]))

return true;

}

return false;

}

public void setAvailableUserNames(String[] usedNames){

String[] names = new String[this.possibleNames.size()];

names = this.possibleNames.toArray(names);

for(int i=0;i<usedNames.length;i++){

if(isUsed(usedNames[i],names)){

int index = this.possibleNames.indexOf(usedNames[i]);

this.possibleNames.remove(index);

names = new String[this.possibleNames.size()];

names = this.possibleNames.toArray(names);

}

}

}

public boolean isValidName(String str){

if(str.length()==0) return false;

for(int i=0;i<str.length();i++){

if(str.charAt(i)<'a'||str.charAt(i)>'z' && (str.charAt(i)<'A' || str.charAt(i)>'Z'))

return false;

}

return true;

}

public static void main(String[] args) {

UserName person1 = new UserName("john","smith");

System.out.println(person1.possibleNames);

String[] used = {"harta","hartm","harty"};

UserName person2 = new UserName("mary","hart");

System.out.println("possibleNames before removing: "+person2.possibleNames);

person2.setAvailableUserNames(used);

System.out.println("possibleNames after removing: "+person2.possibleNames);

}

}

You might be interested in
Rosa is a high school freshman with no savings. She wants to buy a new smartphone in a few months for $300. Which account type b
Iteru [2.4K]
Simple savings account
6 0
2 years ago
Read 2 more answers
________ and wpa are wireless security protocols which use encryption to secure wi_fi networks.
ra1l [238]
Im pretty sure its WEP :)
7 0
3 years ago
What to do if India block your pc​
PIT_PIT [208]

Answer:

Download a VPN xD

8 0
2 years ago
Read 2 more answers
The ____ data source class that reduce your need for accessing individual Data Provider class when you are connecting to an Acce
olasank [31]

Answer:

AccessDataSource

Explanation:

6 0
2 years ago
Differentiate between rotational delay and seek time​
Savatey [412]

Answer:

Seek time measures the delay for the disk head to reach the track. A rotational delay accounts for the time to get to the right sector.

Explanation:

5 0
3 years ago
Other questions:
  • Press the ENTER key to do what?
    12·1 answer
  • Does anybody know if that apple watch is actually worth what it costs?
    9·2 answers
  • You get a BRAINLIEST if you help me ASAP!
    11·2 answers
  • Mobile devices need to work within limited screen space ? true or false
    9·2 answers
  • Which of the following is an example of new and emerging classes of software?
    11·1 answer
  • A customer survey asked respondents to indicate their highest levels of education. The only three choices in the survey were hig
    15·1 answer
  • "What technology will examine the current state of a network device before allowing it can to connect to the network and force a
    13·1 answer
  • What is a file type and why is it important? Give at least three examples of file
    7·1 answer
  • Podcasts can only be created by professional organizations
    11·2 answers
  • Print numbers 0, 1, 2, ..., userNum as shown, with each number indented by that number of spaces. For each printed line, print t
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!