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.
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:
The following mutator methods should be provided to change the attributes:
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".