Class Inventory

java.lang.Object
  extended by Inventory

public class Inventory
extends java.lang.Object


Field Summary
private static int AMMO_POS
          The value corresponding to ammunition in the inventory
private  int ammunition
          The amount of ammunition in the Inventory
private  int food
          The amount of food available in the Inventory
private static int FOOD_POS
          The value corresponding to food in the inventory
private  double money
          The amount of money available in the Inventory.
private static int MONEY_POS
          The value corresponding to money in the inventory
private static int NUM_ITEMS
          total number of items in inventory
private  int oxen
          The amount of propulsion (oxen, rockets, etc.
private static int OXEN_POS
          The value corresponding to any form of propulsion in the inventory
 
Constructor Summary
Inventory()
          Default constructor
Inventory(int theFood, double theMoney, int theAmmo, int theOxen)
          Specific four-parameter constructor.
 
Method Summary
 void add(int item, int amount)
          Adds specified amount of item to Inventory This applies only to tradeable items: food, ammunition, and propulsion Items may correspond to FOOD_POS,AMMO_POS, or OXEN_POS
 int getAmmunition()
           
 int getAmount(int item)
          Returns the amount of the specified item.
 double getCost(int item, double priceFactor)
          Returns the cost of the item at the current Depot's price factor.
 int getFood()
           
 double getMoney()
           
static int getNumItems()
           
 int getOxen()
           
 void printInventory(double priceFactor)
          Prints the Inventory and displays the amount of money available.
 void printInventory(double priceFactor, boolean showMoney)
          Prints the Inventory, possibly displaying the amount of money available
 void remove(int item)
          Removes ALL of a particular item type from an Inventory This applies only to tradeable items: food, ammunition, and propulsion Items may correspond to FOOD_POS,AMMO_POS, or OXEN_POS
 void remove(int item, int amount)
          Removes specified amount of a particular item from an Inventory This applies only to tradeable items: food, ammunition, and propulsion Items may correspond to FOOD_POS,AMMO_POS, or OXEN_POS
 void setAmmunition(int ammunition)
           
 void setFood(int food)
           
 void setMoney(double money)
           
 void setOxen(int oxen)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MONEY_POS

private static final int MONEY_POS
The value corresponding to money in the inventory

See Also:
Constant Field Values

FOOD_POS

private static final int FOOD_POS
The value corresponding to food in the inventory

See Also:
Constant Field Values

AMMO_POS

private static final int AMMO_POS
The value corresponding to ammunition in the inventory

See Also:
Constant Field Values

OXEN_POS

private static final int OXEN_POS
The value corresponding to any form of propulsion in the inventory

See Also:
Constant Field Values

NUM_ITEMS

private static final int NUM_ITEMS
total number of items in inventory

See Also:
Constant Field Values

food

private int food
The amount of food available in the Inventory


money

private double money
The amount of money available in the Inventory. Default starting value: Game.STARTING_MONEY


ammunition

private int ammunition
The amount of ammunition in the Inventory


oxen

private int oxen
The amount of propulsion (oxen, rockets, etc. ) in the Inventory

Constructor Detail

Inventory

public Inventory()
Default constructor


Inventory

public Inventory(int theFood,
                 double theMoney,
                 int theAmmo,
                 int theOxen)
Specific four-parameter constructor. Checks the given parameters for validity and initializes the Inventory properties using those values. All inventory values should be non-negative (zero or greater)

Parameters:
theFood - The amount of food to initialize the Inventory with
theMoney - The amount of money to initialize the Inventory with
theAmmo - The amount of ammunittion to initalize the Inventory with
theOxen - The number of propulsion units (oxen, rockets, etc.) to initialize the Inventory with.
Method Detail

getAmmunition

public int getAmmunition()
Returns:
Returns the ammunition.

setAmmunition

public void setAmmunition(int ammunition)
Parameters:
ammunition - The ammunition to set.

getFood

public int getFood()
Returns:
Returns the food.

setFood

public void setFood(int food)
Parameters:
food - The food to set.

getMoney

public double getMoney()
Returns:
Returns the money.

setMoney

public void setMoney(double money)
Parameters:
money - The money to set.

getOxen

public int getOxen()
Returns:
Returns the oxen.

setOxen

public void setOxen(int oxen)
Parameters:
oxen - The oxen to set.

getNumItems

public static int getNumItems()
Returns:
Returns the value of NUM_ITEMS

getCost

public double getCost(int item,
                      double priceFactor)
Returns the cost of the item at the current Depot's price factor. This method should return the cost of any tradeable item. (Money is not tradeable.) Tradeable items are: food, ammunition, and propulsion (oxen, rockets, etc.) The cost is calculated as the product of the given priceFactor and either Game.DEFAULT_FOOD_COST, Game.DEFAULT_AMMO_COST, or Game.DEFAULT_OXEN_COST, depending on which item is specified. If an invalid item number is provided, then -1.0 is returned.

Parameters:
item - The item ID number which specifies which type of item.
priceFactor - The market factor for the depot.
Returns:
The cost of the specified item at the current price factor.

getAmount

public int getAmount(int item)
Returns the amount of the specified item. This method should return the amount available of any tradeable item. (Money is not tradeable.) Tradeable items are: food, ammunition, and propulsion (oxen, rockets, etc.) The amount of the specified item is returned. In the case of food, which is a double, the amount of food is rounded and cast to int.

Parameters:
item - The item type
Returns:
The amount of the item in the Inventory.

remove

public void remove(int item)
Removes ALL of a particular item type from an Inventory This applies only to tradeable items: food, ammunition, and propulsion Items may correspond to FOOD_POS,AMMO_POS, or OXEN_POS

Parameters:
item - The item type

remove

public void remove(int item,
                   int amount)
Removes specified amount of a particular item from an Inventory This applies only to tradeable items: food, ammunition, and propulsion Items may correspond to FOOD_POS,AMMO_POS, or OXEN_POS

Parameters:
item - The item type
amount - The amount of the item to remove

add

public void add(int item,
                int amount)
Adds specified amount of item to Inventory This applies only to tradeable items: food, ammunition, and propulsion Items may correspond to FOOD_POS,AMMO_POS, or OXEN_POS

Parameters:
item - The item type to add to the Inventory
amount - The amount of the item to add to the Inventory

printInventory

public void printInventory(double priceFactor)
Prints the Inventory and displays the amount of money available. Calls printInventory(double priceFactor, boolean showMoney)

Parameters:
priceFactor - The Depot's price factor

printInventory

public void printInventory(double priceFactor,
                           boolean showMoney)
Prints the Inventory, possibly displaying the amount of money available

Parameters:
priceFactor - The Depot's price factor
showMoney - Flag to indicate whether to display the amount of money available. If true, display money. If false, do not display money.