ope.shopping2
Class Product

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

public class Product
extends java.lang.Object

This class represents a product which has a name and a price. The product can be placed into a shopping cart.

Version:
0.2
Author:
Kimmo Kiiski, Teemu Koskinen
See Also:
ShoppingCart

Constructor Summary
Product(java.lang.String name, double price, int stockCount)
          Creates a new product with the given name and price.
 
Method Summary
 int addStock(int amount)
          Increases the stock count of this product by given amount.
 java.lang.String getName()
          Returns the name of this product.
 double getPrice()
          Returns the price of this product.
 int getStockCount()
          Returns the stock count of this product.
 boolean inStock()
          Tells if the product is in stock or not.
 boolean reduceStock()
          Reduces the product's stock count by one, if it's available.
 java.lang.String toString()
          Overrides Object-classes toString method which creates a String representation for this Product instance.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Product

public Product(java.lang.String name,
               double price,
               int stockCount)
Creates a new product with the given name and price.

Parameters:
name - the name of this product
price - the price of this product
Method Detail

getName

public java.lang.String getName()
Returns the name of this product.

Returns:
the name of this product.

getPrice

public double getPrice()
Returns the price of this product.

Returns:
the price of this product.

getStockCount

public int getStockCount()
Returns the stock count of this product.

Returns:
the stock count of this product.

addStock

public int addStock(int amount)
Increases the stock count of this product by given amount.

Returns:
the new stock count of this product.

inStock

public boolean inStock()
Tells if the product is in stock or not.

Returns:
boolean value indicating if the product is available.

reduceStock

public boolean reduceStock()
Reduces the product's stock count by one, if it's available.

Returns:
boolean value indicating if the reduction succeeded.

toString

public java.lang.String toString()
Overrides Object-classes toString method which creates a String representation for this Product instance.

Overrides:
toString in class java.lang.Object
Returns:
String representation of this product.