Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This question involves an implementation of the class ReviewedProduct that tracks reviews for a product. A ReviewedProduct object is created with one parameter, the product's

This question involves an implementation of the class ReviewedProduct that tracks reviews for a product. A ReviewedProduct object is created with one parameter, the product's name (a String). The ReviewedProduct class provides one constructor and the following four methods: addReview, a void method that takes one integer parameter, the number of stars, and updates the relevant instance variables. The number of stars passed to addReview is always from 1 to 5; this can be assumed to be a precondition. avgStars, which returns a double value. It returns the average number of stars for all reviews, rounded to the nearest half-star. avgStars returns 0.0 if no reviews have been entered for this product yet. isBad, which returns a boolean value. isBad returns true if the product has been reviewed at least three times and at least half of the reviews were one-star reviews; otherwise isBad returns false. toString, which overrides Object's toString method and returns the name of this product followed by the average number of stars and the word "stars". The following table contains a sample code execution sequence and the corresponding results. The average for all reviews added so far, rounded (up) to half-star.

Statements and Expressions Value Returned (blank if no value) Comment ReviewedProduct pr = new ReviewedProduct("Widget"); A new product pr is created. pr.avgStars(); 0.0 No reviews have been added yet. pr.addReview(1); A one-star review added. pr.isBad(); false pr.addReview(1); A one-star review added. pr.isBad(); false pr.addReview(5); A five-star review added. pr.isBad(); true pr.addReview(2); A two-star review added. pr.isBad(); true pr.avgStars(); 2.5 pr.addReview(1); A one-star review added. pr.isBad(); true pr.avgStars(); 2.0 The average for all reviews, 10/5, rounded to the nearest one-half. System.out.println(pr); Displays Widget 2.0 stars

\Write the complete ReviewedProduct class, including the constructor and any required instance variables and methods. Do not use any arrays or lists. Your implementation must meet the above specifications, conform to the example, and be consistent with the information hiding principle. Question 2 public class ReviewedProduct

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Information And Database Systems Asian Conference Aciids 2012 Kaohsiung Taiwan March 2012 Proceedings Part 2 Lnai 7197

Authors: Jeng-Shyang Pan ,Shyi-Ming Chen ,Ngoc-Thanh Nguyen

2012th Edition

3642284892, 978-3642284892

More Books

Students also viewed these Databases questions

Question

Define organisational structure

Answered: 1 week ago

Question

Define line and staff authority

Answered: 1 week ago

Question

Define the process of communication

Answered: 1 week ago

Question

Explain the importance of effective communication

Answered: 1 week ago

Question

* What is the importance of soil testing in civil engineering?

Answered: 1 week ago

Question

sharing of non-material benefits such as time and affection;

Answered: 1 week ago