Next page | Contents page |

Exercise 21 - Product

Write a class called Product to represent a product for sale in an on-line ordering system.

A Product has 3 private fields: description and code of type String, and cost in Euros of type int (just whole numbers of Euros).

Provide overridden versions of the usual 4 methods: toString (), equals (), hashCode (), clone ().

toString () should return something like "Product: description [code] €123". (The character code for the Euro sign is \u20ac.)

Also include a main () method as a test harness. Run that and test the class as completely as possible.

We will use this class again in a later exercise, so make as polished a job of it as you can.

Next page | Contents page |