Class Inventory

java.lang.Object
  extended by Inventory

public class Inventory
extends java.lang.Object

This class represents the inventory of a ve or a vehicle or a market in our game. It keeps track of the cargo available.


Field Summary
private  Cargo[] cargo
          The array of Cargo objects
 
Constructor Summary
Inventory()
          The default constructor, creates an inventory of size equal to the maximum inventory size
Inventory(int size)
          The specific constructor, creates an inventory with size equal to the value passed
 
Method Summary
 boolean add(Cargo goods)
          Adds the cargo passed to the inventory and returns true if the addition was successful, false if not (there is no space in the inventory for it)
 boolean addCargo(Cargo goods)
          There was some confusion over whether to name the method add() or addCargo(), so this method does the exact same thing as the add() method
 Cargo get(int which)
          There was some confusion over whether to name the method get() or getCargo(), so this method does the exact same thing as the getCargo() method
 Cargo[] getCargo()
          Get the Cargo value.
 Cargo getCargo(int which)
          Returns the cargo found in the inventory at the position specified
 int getNumberCargos()
          Returns the number of cargo in the inventory
 boolean isInInventory(java.lang.String type)
          Determines if the cargo type specifed is in the inventory
 void printInventory()
          Prints the contents of the inventory
 void printInventoryWithNumbers(double marketCostFactor)
          Prints the contents of the inventory specifying the amount of each type of cargo and the cost for each type of cargo
 Cargo remove(int index)
          There was some confusion over whether to name the method remove() or removeCargo(), so this method does the exact same thing as the removeCargo() method
 Cargo removeCargo(int index)
          Removes and returns the cargo at the specified position from the inventory (adjusting the positions of the remaining cargo as necessary)
 void setCargo(Cargo[] newCargo)
          Set the Cargo value.
 java.lang.String toString()
          Returns a String representation of the contents of the inventory
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

cargo

private Cargo[] cargo
The array of Cargo objects

Constructor Detail

Inventory

public Inventory()
The default constructor, creates an inventory of size equal to the maximum inventory size


Inventory

public Inventory(int size)
The specific constructor, creates an inventory with size equal to the value passed

Parameters:
size - An int value representing the size of the inventory
Method Detail

getCargo

public Cargo[] getCargo()
Get the Cargo value.

Returns:
the Cargo value.

setCargo

public void setCargo(Cargo[] newCargo)
Set the Cargo value.

Parameters:
newCargo - The new Cargo value.

isInInventory

public boolean isInInventory(java.lang.String type)
Determines if the cargo type specifed is in the inventory

Parameters:
type - A String value indicating the type of cargo to look for
Returns:
true if the cargo type is found in the inventory, false if not

getNumberCargos

public int getNumberCargos()
Returns the number of cargo in the inventory

Returns:
the number of cargo in the inventory

addCargo

public boolean addCargo(Cargo goods)
There was some confusion over whether to name the method add() or addCargo(), so this method does the exact same thing as the add() method

Parameters:
goods - the cargo to add to the Inventory.
Returns:
true upon successful addition ofthe cargo specified, false if not added

add

public boolean add(Cargo goods)
Adds the cargo passed to the inventory and returns true if the addition was successful, false if not (there is no space in the inventory for it)

Parameters:
goods - the cargo to add to the Inventory.
Returns:
true upon successful addition ofthe cargo specified, false if not added

remove

public Cargo remove(int index)
There was some confusion over whether to name the method remove() or removeCargo(), so this method does the exact same thing as the removeCargo() method

Parameters:
index - The position in the array, of the cargo to be removed
Returns:
The Cargo at the position passed

removeCargo

public Cargo removeCargo(int index)
Removes and returns the cargo at the specified position from the inventory (adjusting the positions of the remaining cargo as necessary)

Parameters:
index - The position in the array, of the cargo to be removed
Returns:
The Cargo at the position passed

toString

public java.lang.String toString()
Returns a String representation of the contents of the inventory

Overrides:
toString in class java.lang.Object
Returns:
a String representation of the cargo in the inventory

printInventory

public void printInventory()
Prints the contents of the inventory


printInventoryWithNumbers

public void printInventoryWithNumbers(double marketCostFactor)
Prints the contents of the inventory specifying the amount of each type of cargo and the cost for each type of cargo

Parameters:
marketCostFactor - A double value indicating the cost factor at the current market

get

public Cargo get(int which)
There was some confusion over whether to name the method get() or getCargo(), so this method does the exact same thing as the getCargo() method

Parameters:
which - The position in the array of the cargo to be returned
Returns:
the cargo at the position passed

getCargo

public Cargo getCargo(int which)
Returns the cargo found in the inventory at the position specified

Parameters:
which - The position in the array of the cargo to be returned
Returns:
the cargo at the position passed