I have defined a class called Products (attached file)
The class has a method getNumInStock() to return the numbers in stock for any Product object I've created
I have made 2 objects called sprocket and wrench and can set the numbers of each in stock using a driver program.
My problem:
Add a method to the Product class called compareTo which takes a parameter specifying
another product- and returns an integer satisfying the following conditions:
0 if this product has the same number of items in stock as the other product
< 0 if this product has fewer items in stock than the other product
> 0 if this course has more items in stock than the other product
Fine, except from inside this new method, I can't retrieve the numbers in stock of objects. My effort at doing so is in line 41 of the attached file.
If any knowledgeable person is masochistic enough, or altruistic enough to explain how to do this, I would be really greatful.
thanks
tony
The class has a method getNumInStock() to return the numbers in stock for any Product object I've created
I have made 2 objects called sprocket and wrench and can set the numbers of each in stock using a driver program.
My problem:
Add a method to the Product class called compareTo which takes a parameter specifying
another product- and returns an integer satisfying the following conditions:
0 if this product has the same number of items in stock as the other product
< 0 if this product has fewer items in stock than the other product
> 0 if this course has more items in stock than the other product
Fine, except from inside this new method, I can't retrieve the numbers in stock of objects. My effort at doing so is in line 41 of the attached file.
If any knowledgeable person is masochistic enough, or altruistic enough to explain how to do this, I would be really greatful.
thanks
tony



) overriden method is never called.
- carpe noctem