G.12.3. Class Invoice
We now create class Invoice
(Fig. G.24) to represent a simple invoice that contains billing information for only one kind of part. The class declares private
instance variables partNumber
, partDescription
, quantity
and pricePerItem
(in lines 6–9) that indicate the part number, a description of the part, the quantity of the part ordered and the price per item. Class Invoice
also contains a constructor (lines 12–19), get and set methods (lines 22–74) that manipulate the class’s instance variables and a toString
method (lines 77–83) that returns a String
representation of an Invoice
object. Methods setQuantity
(lines 46–52) and setPricePerItem
(lines 61–68) ensure that quantity
and pricePerItem
obtain only nonnegative values. ...
Get Android™ How to Program, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.