Review class

The Review class describes the review of a Book. It has following attributes:

Attribute name Attribute type Description
numberOfReviews int the number of Reviews
sumOfRatings double the sum of all ratings
average double the average of ratings

The following constructor should be provided to initialize each attribute: public Review()

This constructor initializes numberOfReviews to 0 and sumOfRatings and average to 0.0.

The following method should be provided to increase the number of Reviews by 1 and the sum of Rating by adding the parameter rating. If the number of reviews is greater than 0, then its average (rating) needs to be computed. Otherwise, the average should be set to 0.0.

public void updateRating(double rating)

The following method must be defined:

public String toString()

The toString() method constructs a string of the following form: Reviews:t0.00(0)

where 0.00 is the average (only two digits after the decimal point should be shown - use DecimalFormat class) and 0 within the parenthesis is the number of reviews. Note that the average and the number of reviews can be changed to some other values.

Book class

The Book class describes a book that a customer can give a review/rating. It must have the following attributes:

Attribute name Attribute type Description
title String The title of the Book
publisher String The publisher of the Book
bookReview Review The review of the Book

The following constructor should be provided to initialize each attribute: public Book()

This constructor initializes all strings to "?", and instantiates an object of Review (i.e., call the constructor of the Review class to create an object of Review).

The following accessor methods should be provided to get the attributes:

  • public String getTitle()
  • public String getPublisher()
  • public Review getReview()

The following mutator methods should be provided to change the attributes:

  • public void setTitle(String aTitle)
  • public void setPublisher(String aPublisher)

The following mutator method should be provided to change the review. It should call updateRating method of the Review class:

public void addRating(double rate)

The following method must be defined: public String toString()

The toString() method constructs a string of the following format:

nTitle:tIntroduction to Java Programming,n
Publisher:tPearson,n
Reviews:t0.00(0)nn

You can make use of the DecimalFormat class in java.text package to format the average having two digits after the a decimal point "0.00".

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.