Class StoreBulkItem

java.lang.Object
edu.uw.tcss.model.StoreBulkItem
All Implemented Interfaces:
Item

public final class StoreBulkItem extends Object implements Item
Represents an item with bulk pricing available for members.

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 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 item
      thePrice - the unit price of the item
      theBulkQuantity - the quantity required for bulk pricing
      theBulkPrice - the discounted price for the bulk quantity
      Throws:
      NullPointerException - if theName, thePrice, or theBulkPrice is null
      IllegalArgumentException - if theName is empty, thePrice is negative, theBulkQuantity is negative, or theBulkPrice is negative
  • Method Details

    • getName

      public String getName()
      Returns the name for this Item.
      Specified by:
      getName in interface Item
      Returns:
      the name of this item
    • getPrice

      public BigDecimal getPrice()
      Returns the unit price for this Item. This is the price for a single unit, used for display.
      Specified by:
      getPrice in interface Item
      Returns:
      the unit price of this item
    • calculateTotal

      public BigDecimal calculateTotal(int theQuantity, boolean theUseMembershipPricing)
      Calculates the total price for the given quantity.

      If theUseMembershipPricing is false OR bulkQuantity is 0, returns price × 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:
      calculateTotal in interface Item
      Parameters:
      theQuantity - the quantity to calculate the total for
      theUseMembershipPricing - true to apply bulk pricing for members
      Returns:
      the total price for the given quantity
      Throws:
      IllegalArgumentException - if theQuantity is negative
    • getFormattedDescription

      public String 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:
      getFormattedDescription in interface Item
      Returns:
      a formatted description string
    • toString

      public String toString()
      Returns a debug representation of this item.

      The exact format is not specified and should not be relied upon.

      Overrides:
      toString in class Object
      Returns:
      a string representation for debugging
    • equals

      public boolean equals(Object theOther)
      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.

      Overrides:
      equals in class Object
      Parameters:
      theOther - the object to compare to
      Returns:
      true if the objects are equal, false otherwise
    • hashCode

      public int hashCode()
      Returns a hash code consistent with equals(Object).
      Overrides:
      hashCode in class Object
      Returns:
      a hash code for this item