November 14th, 2012, 01:31 PM
Create a class called Product. The class should have private fields for:
1. The product name
2. The product price
The class should have the following methods:
1. a toString method that displays the name of the product and its price.
2. An equals method that compares two Products and returns true if they’re the same price
3. Get and set methods for the private fields
4. Any necessary constructors
The class should throw an IllegalArgumentException when a user attempts to set a price less than 0.
The class should throw an IllegalNameException when a user attempts to set a name equal to the empty string.
The IllegalNameException should be a derived class based on the IllegalArgumentException class.
Click Here to Expand Forum to Full Width
This is a CodeGuru survey question.