Class StoreCart
java.lang.Object
edu.uw.tcss.model.StoreCart
- All Implemented Interfaces:
Cart
Implementation of a shopping cart for the bookstore.
This cart stores ItemOrder objects, ensuring only one order exists per unique Item. When calculating totals, it delegates to each Item to calculate its own total based on quantity and membership status.
- Version:
- Winter 2026
- Author:
- Charles Bryan
-
Nested Class Summary
Nested classes/interfaces inherited from interface Cart
Cart.CartSize -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds an order to the cart.Returns the total cost of all items in the cart.voidclear()Removes all orders from the cart.Returns the current size of the shopping cart.voidsetMembership(boolean theMembership) Sets the customer's membership status.toString()Returns a debug representation of this cart.
-
Constructor Details
-
StoreCart
public StoreCart()Constructs a new empty StoreCart.The customer does not have a membership by default.
-
-
Method Details
-
add
Adds an order to the cart.Replaces any previous order for the same item. If quantity is 0, removes the item from the cart.
- Specified by:
addin interfaceCart- Parameters:
theOrder- the ItemOrder to add- Throws:
NullPointerException- if theOrder is null
-
setMembership
public void setMembership(boolean theMembership) Sets the customer's membership status.Members receive bulk pricing on eligible items.
- Specified by:
setMembershipin interfaceCart- Parameters:
theMembership- true if the customer has a membership
-
calculateTotal
Returns the total cost of all items in the cart.Uses
HALF_EVEN(banker's) rounding with scale of 2.- Specified by:
calculateTotalin interfaceCart- Returns:
- the total cost of the shopping cart
-
clear
-
getCartSize
Returns the current size of the shopping cart.- Specified by:
getCartSizein interfaceCart- Returns:
- a CartSize record with
itemOrderCount(unique items) anditemCount(total quantity)
-
toString
-