-
November 14th, 2012, 02:31 PM
#1
need help
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.
-
November 15th, 2012, 07:09 AM
#2
Re: need help
Ok so that's your homework, what's your question?
-
November 15th, 2012, 07:37 AM
#3
Re: need help
Originally Posted by wojo007
2. An equals method that compares two Products and returns true if they’re the same price
Whoever wrote the specifications for this was a bit sloppy. Simply returning 'true' for any input would fulfil this requirement
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|