Java Reference
In-Depth Information
545
I N V O I C E
Sam's Small
Appliances
100 Main Street
Anytown, CA
98765
Description
Price
Qty
Total
Toaster
29.95
3
89.85
Hair dryer
24.95
1
24.95
Car vacuum
19.99
2
39.98
AMOUNT DUE:
$154.78
Also, in the interest of simplicity, we do not provide a user interface. We just
supply a test program that adds line items to the invoice and then prints it.
12.4.2 CRC Cards
First, you need to discover classes. Classes correspond to nouns in the requirements
description. In this problem, it is pretty obvious what the nouns are:
Invoice
Address
LineItem
Product
Description
Price
Quantity
Total
Amount Due
(Of course, Toaster doesn't countȌit is the description of a LineItem object
and therefore a data value, not the name of a class.)
Description and price are fields of the Product class. What about the quantity?
The quantity is not an attribute of a Product . Just as in the printed invoice, let's
have a class LineItem that records the product and the quantity (such as Ȓ3
toastersȓ).
The total and amount due are computedȌnot stored anywhere. Thus, they don't
lead to classes.
Search WWH ::




Custom Search