Class Market

java.lang.Object
  extended by Market

public class Market
extends java.lang.Object


Field Summary
private  Inventory inventory
          The inventory of this Market
private  double marketCostFactor
          The cost factor for this market -- how expensive things are here
 
Constructor Summary
Market(double costFactor)
          The specific constructor.
 
Method Summary
 void buyItem(Vehicle vehicle)
          Finds the item the vehicle(player) wants to buy in the market's inventory, checks if the player has enough money to buy the item, if so removes it from the market's inventory, adds it to the vehicle's inventory and subtracts the cost from the vechicle's (player's) money.
 void createUniqueInventory(int size)
          Creates a unique inventory for this market by creating 'size' different and new cargo items and adding them to the inventory.
 void enterMarket(Vehicle player)
          The main method for doing an action at a market.
 Inventory getInventory()
          Get the Inventory value.
 double getMarketCostFactor()
          Get the MarketCostFactor value.
 void printInventory()
          Prints the contents of the inventory
 void printMarketCommands()
          Prints the commands available to the player when in the market to the screen
 void sellItem(Vehicle vehicle)
          Finds the item the vehicle(player) wants to sell in its inventory, removes it from the vehicle's inventory, adds it to the market's inventory and adds the cost to the vechicle's (player's) money.
 void setInventory(Inventory newInventory)
          Set the Inventory value.
 void setMarketCostFactor(double newMarketCostFactor)
          Set the MarketCostFactor value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

inventory

private Inventory inventory
The inventory of this Market


marketCostFactor

private double marketCostFactor
The cost factor for this market -- how expensive things are here

Constructor Detail

Market

public Market(double costFactor)
The specific constructor. Initialises the marketCostFactor to the value passed, and creates a unique inventory

Parameters:
costFactor - The cost factor for the market
Method Detail

getInventory

public Inventory getInventory()
Get the Inventory value.

Returns:
the Inventory value.

setInventory

public void setInventory(Inventory newInventory)
Set the Inventory value.

Parameters:
newInventory - The new Inventory value.

getMarketCostFactor

public double getMarketCostFactor()
Get the MarketCostFactor value.

Returns:
the MarketCostFactor value.

setMarketCostFactor

public void setMarketCostFactor(double newMarketCostFactor)
Set the MarketCostFactor value.

Parameters:
newMarketCostFactor - The new MarketCostFactor value.

createUniqueInventory

public void createUniqueInventory(int size)
Creates a unique inventory for this market by creating 'size' different and new cargo items and adding them to the inventory. The cost of each cargo is adjusted to reflect the market's cost factor.

Parameters:
size - The size of the inventory

printInventory

public void printInventory()
Prints the contents of the inventory


printMarketCommands

public void printMarketCommands()
Prints the commands available to the player when in the market to the screen


enterMarket

public void enterMarket(Vehicle player)
The main method for doing an action at a market. This method reads in a command from the keyboard (via Parser.parse()), then takes the appropriate action based on that command. The possible actions include buying cargo, selling cargo, printing the market's inventory (i.e. cargo available for trading), printing the vehicle's inventory, and exiting the market

Parameters:
player - The vehicle entering the market

buyItem

public void buyItem(Vehicle vehicle)
Finds the item the vehicle(player) wants to buy in the market's inventory, checks if the player has enough money to buy the item, if so removes it from the market's inventory, adds it to the vehicle's inventory and subtracts the cost from the vechicle's (player's) money.

Parameters:
vehicle - The vehicle (player) buying the item

sellItem

public void sellItem(Vehicle vehicle)
Finds the item the vehicle(player) wants to sell in its inventory, removes it from the vehicle's inventory, adds it to the market's inventory and adds the cost to the vechicle's (player's) money.

Parameters:
vehicle - The vehicle (player) selling the item