Next page | Contents page |

Exercise 22 - Order

(a)In the previous exercise you wrote a Product class. We now want to start making an on-line ordering system using that class.

First make class Catalogue, to hold Product objects in such a way that the details of any product can be found very quickly from its code.

Then use that in an Order class. A customer may make an order comprising any number of products. Make it flexible: customers are allowed to change their minds and remove some products and add others.

How will you represent the fact that a customer may order several of one product?

Each order should have a reference code, quite separate from any product codes.

The toString () method of Order should list the products ordered and also give the total cost of the order.

(b)Test your new classes. (Make up some Products to put in the Catalogue. Make up some Orders. Etc.)

(c) In a real on-line system each customer will be given a separate thread by the web server, so orders can be made concurrently. Would that have any consequences for the code you have written so far? What if the catalogue is updated while customers are ordering?

Next page | Contents page |