public class ShoppingCart extends Object implements Serializable
Modifier and Type | Method and Description |
---|---|
void |
addItem(Book book,
int quantity)
Add the given book with the given quantity in the cart.
|
void |
changeQuantity(Book book,
int delta)
Change the quantity of the given book by the given delta.
|
void |
clear() |
Customer |
getCustomer()
Gets the Customer who owns this cart.
|
Map<Book,Integer> |
getItems()
Gets the books with their corresponding quantity in this cart.
|
int |
getTotalCount() |
boolean |
isEmpty() |
void |
remove(Book book)
Removes the given book from this cart.
|
public Customer getCustomer()
public Map<Book,Integer> getItems()
public void addItem(Book book, int quantity)
book
- non-null Bookquantity
- a positive quantity.public void changeQuantity(Book book, int delta)
book
- a non-null Book that must exist in this cart.delta
- no. of quantity to change. Can be positive or negative.
If the resultant quantity becomes zero of negative, the book is removed from the cart.public void remove(Book book)
book
- book a non-null Book that must exist in this cart.public void clear()
public boolean isEmpty()
public int getTotalCount()
Copyright © 2006–2018 Apache Software Foundation. All rights reserved.