Question: Create a public class Product. Each product stores a single String name set by the constructor. ( Reject null names using assert. ) Provide only

Create a public class Product. Each product stores a single String name set by the constructor. (Reject null names using assert.) Provide only a getter for the name following our usual naming conventions.
Also store a rating value as an int. Initialize it to 0 in the constructor and provide a setter and getter for it. Your setter should only accept values between 1 and 5, inclusive. Enforce this using assert.
Product should also provide a single class method named betterProduct, which accepts two non-null Products and returns whichever has the better rating. If both ratings are the same, return the first Product.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!