Class ShoppingCart

    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method 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.
      java.util.Map<Book,​java.lang.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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • getCustomer

        public Customer getCustomer()
        Gets the Customer who owns this cart.
        Returns:
        non-null Customer.
      • getItems

        public java.util.Map<Book,​java.lang.Integer> getItems()
        Gets the books with their corresponding quantity in this cart.
      • addItem

        public void addItem​(Book book,
                            int quantity)
        Add the given book with the given quantity in the cart. If the book already exists then the quantity is added to the existing quantity.
        Parameters:
        book - non-null Book
        quantity - a positive quantity.
      • changeQuantity

        public void changeQuantity​(Book book,
                                   int delta)
        Change the quantity of the given book by the given delta.
        Parameters:
        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.
      • remove

        public void remove​(Book book)
        Removes the given book from this cart.
        Parameters:
        book - book a non-null Book that must exist in this cart.
      • clear

        public void clear()
      • isEmpty

        public boolean isEmpty()
      • getTotalCount

        public int getTotalCount()