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]
3 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]3 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
How can development in ICT be utilized to speed up the development and integration efforts
maw [93]

Answer:

Explanation:

1.  Sustainability and scale

2.  Lack of knowledge

 

3. Pace of change

4.  Funding

5. Changing roles and norms

7 0
4 years ago
What do you call the number that is used as an index to pinpoint a specific element within an array?
Pie

Answer:

d. subscript

Explanation:

Although I believe "index" is a better term. The question already says it!

5 0
4 years ago
When delivering digital technologies to clients, what is a best practice to make those solutions sustainable?
lidiya [134]

When delivering digital technologies to clients, a best practice is to: Recommend the client spread out their data centers to distribute energy usage globally.

<h3>What is a computational sustainability?</h3>

Computational sustainability can be defined as a process through which societal, economic, ecological and environmental resources are balanced through the use of various mathematical and computational techniques.

<h3>The importance of computational sustainability</h3>

Generally, computational sustainability helps to produce sufficient amount of energy for the world to globally distribute and support its biological systems.

In order to achieve computational sustainability, it is essential to practice the following:

  • Ensure that software applications are widespread.
  • Clients should spread out their data centers.

In conclusion, a best practice for delivering digital technologies to clients is to recommend a spread out of data centers to distribute energy usage globally.

Read more on computational sustainability here: brainly.com/question/24882256

6 0
3 years ago
How do you convert a decimal to binary?
lidiya [134]
B. repeatedly divide the decimal number by 2
7 0
3 years ago
Read 2 more answers
A .jpg file is an example is an example of which if the following file types
Setler79 [48]
Answer chooses would help but a .jpg is a picture
4 0
3 years ago
Other questions:
  • HELP ASAP!!!! PLEASE !!! What information does the Media Access Control (MAC) on a network card provide?
    9·2 answers
  • In which area of engineering does material selection play a vital role a design optimization b forensic engineering c mechanical
    6·1 answer
  • Scientific models can be used for a variety of different purposes. Which of the following statements about scientific models is
    7·2 answers
  • A chef writing up her famed recipe for beef stew realizes she has switched parsley and oregano everywhere in the recipe. The che
    13·1 answer
  • One side in a Transmission Control Protocol (TCP) connection has not been able to properly recover from a series of malformed se
    6·1 answer
  • How does having weak security on your browser represent the weakest link in a network
    8·1 answer
  • What is a spark line? how is a different a chart​
    14·1 answer
  • Please can someone help my assignment.​
    13·1 answer
  • Alfred works in the human resources department, and he uses a management information system to find applicants' résumés on the w
    7·1 answer
  • In which of the following cases is the application of a nested loop not justified? When comparing two lists of integers When for
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!