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
Which statement is true? Select 3 options.
irina1246 [14]

Answer:

The statements which are true are;

  • A user-defined data type can include other user-defined data types
  • A user-defined data type is defined using a class
  • A user-defined data type can include a list

Explanation:

A user-defined data type (UDT) is a datatype that is defined and derived by the use of the datatypes which preexist including existing user-defined datatypes and the built-in datatypes

It is therefore true that a user-defined data type can include other user-defined data types

A class is a user-defined data type that contains both its member data and member functions, that can be used when an instance of the class is first created

Therefore, a user-defined data type is defined using a class

In a user-defined data type, a variable has actual data within it which can include an array or list

Therefore a user-defined data type can include a list.

3 0
2 years ago
Read 2 more answers
BIE, but plz help me on this ASAP!!! GIVING A BRAINLIEST... For this activity, imagine that you have been asked to teach a frien
WITCHER [35]

Answer:

DM me I have an answer set up but it won't let me here because it's "too long" hope to here back from you! (sorry about this Brainly has been acting up on me lately!!!!!)

Explanation:

3 0
3 years ago
Which query will give the following result when it it applied on table 1????!!!!!
Mandarinka [93]

Answer:

B

Explanation:

You need Name , Age and Gender

the second requirement should only match the last row where age is 20 and gender is male.

thrid requirement of the query is that its syntax should be correct.

Option B staisfies all of required so it is the correct option.

6 0
3 years ago
In c++
Elodia [21]

Answer:

class studentType: public personType

{

public:

virtual void print() = 0;

virtual void calculateGPA() = 0;

void setID(long id) {

studentId = id;

}

void setCourses(const string c[], int noOfC) {

noOfCourses = noOfC;

for (int i=0; i<noOfCourses; i++) {

courses[i] = c[i];

}

}

void setGrades(const char cG[], int noOfC) {

noOfCourses = noOfC;

for (int i=0; i<noOfCourses; i++) {

coursesGrade[i] = cG[i];

}

}

long getID() {

return studentId;

}

string* getCourses() {

return courses;

}

char* getGrades() {

return coursesGrade;

}

studentType(string fName = "", string lastName = "",

long id = 0, string c[] = NULL, char cG[] = NULL, int noOfC = 0);

private:

long studentId;

string courses[6];

char coursesGrade[6];

int noOfCourses;

};

Explanation:

Code rewritten

5 0
3 years ago
Create union floatingPoint with members float f, double d and long double x. Write a program that inputs values of type float, d
Kitty [74]

Answer:

Here the code is given as follows,

#include <stdio.h>

#include <stdlib.h>

union floatingPoint {

float floatNum;

double doubleNum;

long double longDoubleNum;

};

int main() {

union floatingPoint f;

printf("Enter data for type float: ");

scanf("%f", &f.floatNum);

printf("\nfloat %f ", f.floatNum);

printf("\ndouble %f ", f.doubleNum);

printf("\nlong double %Lf ", f.longDoubleNum);

printf("\n\nBreakdown in Hex");

printf("\nfloat in hex %x ", f.floatNum);

printf("\ndouble in hex %x ", f.doubleNum);

printf("\nlong double in hex %Lx ", f.longDoubleNum);

printf("\n\nEnter data for type double: ");

scanf("%lf", &f.doubleNum);

printf("float %f ", f.floatNum);

printf("\ndouble %f ", f.doubleNum);

printf("\nlong double %Lf ", f.longDoubleNum);

printf("\n\nBreakdown in Hex");

printf("\nfloat in hex %x ", f.floatNum);

printf("\ndouble in hex %x ", f.doubleNum);

printf("\nlong double in hex %Lx ", f.longDoubleNum);

printf("\n\nEnter data for type long double: ");

scanf("%Lf", &f.longDoubleNum);

printf("float %f ", f.floatNum);

printf("\ndouble %f ", f.doubleNum);

printf("\nlong double %Lf ", f.longDoubleNum);

printf("\n\nBreakdown in Hex");

printf("\nfloat in hex %x ", f.floatNum);

printf("\ndouble in hex %x ", f.doubleNum);

printf("\nlong double in hex %Lx ", f.longDoubleNum);

return 0;

}

5 0
3 years ago
Other questions:
  • Jason works as an accountant in a department store. He needs to keep a daily record of all the invoices issued by the store. Whi
    5·2 answers
  • Which term is used to describe a password-protected, encrypted data file that verifies the identity of the sender of a message?
    8·1 answer
  • Which of the following button should always be included when designing a navigation pictures escape contact FAQ
    5·2 answers
  • In which phase of the software development process would probing questions be used to verify the problem definition?
    12·1 answer
  • Assume that an array of integers named a that contains exactly five elements has been declared and initialized. Write a single s
    15·1 answer
  • 2.
    5·1 answer
  • What typically happens by default when a file is double clicked in Microsoft Windows?
    9·1 answer
  • In order for a fault-block mountain to form, a ______ must take place along a fault line and one side must be ________.
    11·1 answer
  • Worth 30 pts
    9·2 answers
  • Overview
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!