Class StoreItem

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

public final class StoreItem extends Object implements Item
Represents a simple item with standard pricing (no bulk discounts).

StoreItem handles items that are sold at a fixed unit price regardless of quantity or membership status. The membership parameter in calculateTotal(int, boolean) is ignored for this item type.

Version:
Winter 2026
Author:
Charles Bryan
  • Constructor Details

    • StoreItem

      public StoreItem(String theName, BigDecimal thePrice)
      Constructs a new StoreItem with the given name and price.
      Parameters:
      theName - the name of the item
      thePrice - the unit price of the item
      Throws:
      NullPointerException - if theName or thePrice is null
      IllegalArgumentException - if thePrice is negative or theName is empty
  • 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.

      Returns price × quantity. The membership parameter is ignored for StoreItem — the unit price is always used.

      Specified by:
      calculateTotal in interface Item
      Parameters:
      theQuantity - the quantity to calculate the total for
      theUseMembershipPricing - ignored for StoreItem
      Returns:
      the total price (price × quantity)
      Throws:
      IllegalArgumentException - if theQuantity is negative
    • getFormattedDescription

      public String getFormattedDescription()
      Returns a formatted description suitable for display.

      Format: "name, $price" (e.g., "Computer Science Pen, $2.00").

      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 StoreItem to another object for equality.

      Two StoreItems are equal if they have the same name and price.

      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