Class StoreBulkItem
- All Implemented Interfaces:
Item
Bulk items have a special price when purchased in quantities that meet or exceed the bulk threshold. When membership pricing is enabled, the bulk price is applied to as many complete bulk sets as possible, with any remainder charged at the standard unit price.
Example: An item costs $1.00 each or 10 for $5.00 (bulk). Buying 23 with membership: (2 × $5.00) + (3 × $1.00) = $13.00
- Version:
- Winter 2026
- Author:
- Charles Bryan
-
Constructor Summary
ConstructorsConstructorDescriptionStoreBulkItem(String theName, BigDecimal thePrice, int theBulkQuantity, BigDecimal theBulkPrice) Constructs a new StoreBulkItem with the given name, price, and bulk pricing. -
Method Summary
Modifier and TypeMethodDescriptioncalculateTotal(int theQuantity, boolean theUseMembershipPricing) Calculates the total price for the given quantity.booleanCompares this StoreBulkItem to another object for equality.Returns a formatted description suitable for display.getName()Returns the name for this Item.getPrice()Returns the unit price for this Item.inthashCode()Returns a hash code consistent withequals(Object).toString()Returns a debug representation of this item.
-
Constructor Details
-
StoreBulkItem
public StoreBulkItem(String theName, BigDecimal thePrice, int theBulkQuantity, BigDecimal theBulkPrice) Constructs a new StoreBulkItem with the given name, price, and bulk pricing.- Parameters:
theName- the name of the itemthePrice- the unit price of the itemtheBulkQuantity- the quantity required for bulk pricingtheBulkPrice- the discounted price for the bulk quantity- Throws:
NullPointerException- if theName, thePrice, or theBulkPrice is nullIllegalArgumentException- if theName is empty, thePrice is negative, theBulkQuantity is negative, or theBulkPrice is negative
-
-
Method Details
-
getName
-
getPrice
Returns the unit price for this Item. This is the price for a single unit, used for display. -
calculateTotal
Calculates the total price for the given quantity.If
theUseMembershipPricingis false OR bulkQuantity is 0, returnsprice × quantity.If membership pricing is enabled, applies bulk price to complete sets and unit price to remainder. Example: 23 items at $1.00 each, 10 for $5.00 bulk = (2 × $5.00) + (3 × $1.00) = $13.00.
- Specified by:
calculateTotalin interfaceItem- Parameters:
theQuantity- the quantity to calculate the total fortheUseMembershipPricing- true to apply bulk pricing for members- Returns:
- the total price for the given quantity
- Throws:
IllegalArgumentException- if theQuantity is negative
-
getFormattedDescription
Returns a formatted description suitable for display.Format:
"name, $price (bulkQty for $bulkPrice)"(e.g.,"UW Note pad, $4.41 (6 for $10.04)").If bulkQuantity is 0, omits the bulk pricing portion.
- Specified by:
getFormattedDescriptionin interfaceItem- Returns:
- a formatted description string
-
toString
-
equals
Compares this StoreBulkItem to another object for equality.Two StoreBulkItems are equal if they have the same name, price, bulkQuantity, and bulkPrice.
Note: A StoreItem and StoreBulkItem are NEVER equal, even with identical name and price.
-
hashCode
public int hashCode()Returns a hash code consistent withequals(Object).
-