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
In a multiprogramming and time-sharing environment, several users share the system simultaneously. This situation can result in
kap26 [50]

<u>Explanation:</u>

a.

  • One user can read the private data of another user-privacy.
  • One user can prevent another user from getting anything done-denial of service.

Indeed, in any multiprogramming and time-sharing environment since the computers of users are networked together, then it is very possible for a bad actor to read the private data of another user, or even prevent another user from accessing their computer by employing a denial of service attack on the network. In other words, the network would be unable to handle the request of users since has been overloaded by another user.

b. a. Yes - if we can ensure that the operating system prevents any sharing of data between users, either for reading or writing and fairly shares the computer, then we can achieve the same level of security.

7 0
3 years ago
PLEASE HELP PROGRAMMING WILL GIVE BRAINLIEST
AveGali [126]

Answer:

I think it the answer will be 0,1,2,3,4

Explanation:

7 0
3 years ago
Read 2 more answers
If a user would like to modify margins to specific settings, users would need to select the _____ option.
RSB [31]
If a user would like to modify margins to specific settings, users would need to select the <span><u>Custom Margins</u> </span>option.
4 0
3 years ago
Write a recursive function that takes a non-negative integer as an argument and displays the same number in reverse order (i.e.
avanturin [10]

Answer:

Following are the program in C++ language

#include<iostream> // header file

using namespace std; // namespace std

int reverse(int n1); // function prototype

int main()  // main function()

{

   int num; // Variable declaration

   cout << "Enter the number" << endl;

   cin >> num; // Read the number bu the user

  cout<<"After Reverse the digit:\n";

   int res= reverse(num); // calling function reverse

   

   cout<<res; // display  

}

int reverse(int n1) // function definition of reverse

{

   if (n1<10)  // checking the base condition

       {

           return n1;

       }

   else

       {

           cout << n1 % 10; // Printed the last digit

          return reverse(n1/10); // calling itsself

}

}

Output:

Enter the number:

76538

After Reverse the digit:

83567

Explanation:

Following are the description of the program

  • In the main function read the number by user in the "num" variable of int type.
  • Calling the reverse and pass that "num" variable into it.
  • After calling the control moves to the body of the reverse function.In this function we check the two condition

        1  base condition

   if (n1<10)  // checking the base condition

       {

           return n1;

     }

      2  General condition

  else

       {

           cout << n1 % 10; // Printed the last digit

          return reverse(n1/10); // calling itsself

       }

  • Finally return the reverse number and display them into the main function.
5 0
3 years ago
Assume the user types in 7 and 10. What is output by the following?
Marianna [84]

Answer:

Enter a number: 7

Enter a number: 10

Traceback (most recent call last):

 File "main.py", line 3, in <module>

   print (numi + num2)

NameError: name 'numi' is not defined

Explanation:

The typo in the print statement causes a run-time error, where obviously num1+num2 was expected, and an output of 17.

3 0
3 years ago
Other questions:
  • What are the 6 external parts of a computer system
    8·1 answer
  • Java languageThe cost to ship a package is a flat fee of 75 cents plus 25 cents per pound.1. Declare a constant named CENTS_PER_
    5·2 answers
  • Explain how Deep Packet Inspection works (DPI). How is this technology beneficial to Perimeter Security? Lastly, describe a scen
    6·1 answer
  • How to Save Power-Point presentation as a single file Web page that can be uploaded to the World Wide Web ?
    14·1 answer
  • Statistics are often calculated with varying amounts of input data. Write a program that takes any number of non-negative intege
    10·1 answer
  • What effect on total current flow will a shorted series component have in a series-parallel circuit?
    8·1 answer
  • A technician has been asked to upgrade a processor and needs to do some research. The computer is just a couple of years old. Wh
    13·1 answer
  • PLEASE HELP I mainly only need the answer for 4.
    5·1 answer
  • Write the two features of a mouse.​
    9·1 answer
  • What is the two’s compliment of -95,-122,-111,-57
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!