ope.shopping2
Class ShoppingCart

java.lang.Object
  extended by ope.shopping2.ShoppingCart

public class ShoppingCart
extends java.lang.Object

This class represents a shopping cart. A shopping cart has a customer as an owner and a list of products.

Version:
0.2
Author:
Kimmo Kiiski, Teemu Koskinen
See Also:
Customer, Product

Constructor Summary
ShoppingCart()
          Creates a new empty and anonymous shopping cart.
 
Method Summary
 void addProduct(Product item)
          Adds a product to the shopping cart if it is available.
 void clear()
          Removes all the products from the shopping cart.
 int countProducts()
          Returns the number of products in this shopping cart.
 Product getProduct(int index)
          Returns a product at the given index in this shopping cart.
 double getTotalPrice()
          Calculates the total price of products in this shopping cart.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ShoppingCart

public ShoppingCart()
Creates a new empty and anonymous shopping cart.

Method Detail

addProduct

public void addProduct(Product item)
Adds a product to the shopping cart if it is available. Also calls the reduceStock-method that updates the stock count for this Product.

Parameters:
item - the product to be added.

countProducts

public int countProducts()
Returns the number of products in this shopping cart.

Returns:
the number of products in this shopping cart.

getProduct

public Product getProduct(int index)
Returns a product at the given index in this shopping cart.

Parameters:
index - the index of the product.
Returns:
the product at the given index.

clear

public void clear()
Removes all the products from the shopping cart.


getTotalPrice

public double getTotalPrice()
Calculates the total price of products in this shopping cart.

Returns:
the total price of products in this shopping cart.