Class StoreItem
java.lang.Object
edu.uw.tcss.model.StoreItem
- All Implemented Interfaces:
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 Summary
ConstructorsConstructorDescriptionStoreItem(String theName, BigDecimal thePrice) Constructs a new StoreItem with the given name and price. -
Method Summary
Modifier and TypeMethodDescriptioncalculateTotal(int theQuantity, boolean theUseMembershipPricing) Calculates the total price for the given quantity.booleanCompares this StoreItem 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
-
StoreItem
Constructs a new StoreItem with the given name and price.- Parameters:
theName- the name of the itemthePrice- the unit price of the item- Throws:
NullPointerException- if theName or thePrice is nullIllegalArgumentException- if thePrice is negative or theName is empty
-
-
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.Returns
price × quantity. The membership parameter is ignored for StoreItem — the unit price is always used.- Specified by:
calculateTotalin interfaceItem- Parameters:
theQuantity- the quantity to calculate the total fortheUseMembershipPricing- ignored for StoreItem- Returns:
- the total price (
price × quantity) - Throws:
IllegalArgumentException- if theQuantity is negative
-
getFormattedDescription
Returns a formatted description suitable for display.Format:
"name, $price"(e.g.,"Computer Science Pen, $2.00").- Specified by:
getFormattedDescriptionin interfaceItem- Returns:
- a formatted description string
-
toString
-
equals
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.
-
hashCode
public int hashCode()Returns a hash code consistent withequals(Object).
-