Package cs2110
Class SingleItem
java.lang.Object
cs2110.SingleItem
- All Implemented Interfaces:
Item
Represents grocery store items that are priced and purchased by unit, such as a box of pasta, a
can of soup, etc. Each instance represents one unit of its corresponding product.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionSingleItem
(long code, String name, int cost) Create an Item representing one unit of the product with UPC code `code` and name `name`, which costs `cost` cents. -
Method Summary
-
Field Details
-
code
private final long codeThe UPC code for this item's product; must be positive. -
name
The name of this item's product; must be non-empty. -
cost
private final int costThe cost of this item in cents; must be non-negative.
-
-
Constructor Details
-
SingleItem
Create an Item representing one unit of the product with UPC code `code` and name `name`, which costs `cost` cents. Requires `code` is positive, `name` is non-empty, and `cost` is non-negative.
-
-
Method Details
-
itemCode
public long itemCode()Return the UPC code for this item's product. -
name
Return the name of this item's product. -
cost
public int cost()Return the cost of this item, in cents. -
formatForReceipt
Return a description of this item to be printed on a receipt. This consists of the name of the item and its cost (formatted in the usual $x.xx manner), separated by a tab (\t) character.- Specified by:
formatForReceipt
in interfaceItem
-