ope.shopping
Class ShoppingCart

java.lang.Object
  extended by ope.shopping.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.1
Author:
Kimmo Kiiski, Teemu Koskinen
See Also:
Person, Product

Constructor Summary
ShoppingCart(Person customer)
          Creates a new empty shopping cart.
 
Method Summary
 void addProduct(Product item)
          Adds a product to the shopping cart.
 boolean checkOut()
          Checks out this shopping cart.
 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(Person customer)
Creates a new empty shopping cart.

Parameters:
customer - the owner of the new shopping cart
Method Detail

addProduct

public void addProduct(Product item)
Adds a product to the shopping cart.

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.

checkOut

public boolean checkOut()
Checks out this shopping cart. The customer of the shopping cart will be charged and the cart will be cleared. If the customer cannot afford to buy products, money won't be charged and the cart will remain unchanged. A standard output message is printed, which describes whether the purchase was successful or not.

Returns:
whether the customer had enough money to buy the products.