Class Parser

java.lang.Object
  extended by Parser

public class Parser
extends java.lang.Object

This class is used to get commands as user input from the keyboard. For full This class does not have a constructor, and all it's methods are static. Thus, they are called by Parser.parse(), for example.


Field Summary
static int AVAILABLE
          The value that parse() returns if the user enters 'available' to see what is available to buy at the current market.
static int BUY
          The value that parse() returns if the user enters 'buy' to buy cargo at the current market.
static int DO_NOT_UNDERSTAND
          The value that parse() returns if it did not understand what the user entered.
static int EXIT_MARKET
          The value that parse() returns if the user enters 'exit' to exit the market and return to the location.
static int INVENTORY
          The value that parse() returns if the user enters 'inventory' to display his/her inventory.
static int MARKET
          The value that parse() returns if the user enters 'market' to enter the market at teh current location.
static int QUIT
          The value that parse() returns if the user enters 'quit' to quit the game.
static int SELL
          The value that parse() returns if the user enters 'sell' sell cargo at the current market.
private static java.util.Scanner stdin
          The Scanner object that is used by the various Parser methods
static int TRAVEL
          The value that parse() returns if the user enters 'travel' to travel to another location in the universe.
static int WORLDMAP
          The value that parse() returns if the user enters 'worldmap' to print the map of the universe.
 
Constructor Summary
private Parser()
          Making the constructor private prevents anybody from calling it (as we don't want to create objects of this class
 
Method Summary
static Location getDestination()
          This method asks the user to enter the name of the location to travel to, having indicated that he/she wants to travel to a new location
static int getItemToTrade(Inventory inventory, double marketCostFactor)
          This method asks the user to enter the number corresponding to the items he/she wants to trade
static int parse()
          This method reads in the user's input from the keyboard, and returns a value corresponding to what the user entered.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

QUIT

public static final int QUIT
The value that parse() returns if the user enters 'quit' to quit the game.

See Also:
Constant Field Values

INVENTORY

public static final int INVENTORY
The value that parse() returns if the user enters 'inventory' to display his/her inventory.

See Also:
Constant Field Values

BUY

public static final int BUY
The value that parse() returns if the user enters 'buy' to buy cargo at the current market.

See Also:
Constant Field Values

TRAVEL

public static final int TRAVEL
The value that parse() returns if the user enters 'travel' to travel to another location in the universe.

See Also:
Constant Field Values

MARKET

public static final int MARKET
The value that parse() returns if the user enters 'market' to enter the market at teh current location.

See Also:
Constant Field Values

EXIT_MARKET

public static final int EXIT_MARKET
The value that parse() returns if the user enters 'exit' to exit the market and return to the location.

See Also:
Constant Field Values

WORLDMAP

public static final int WORLDMAP
The value that parse() returns if the user enters 'worldmap' to print the map of the universe.

See Also:
Constant Field Values

SELL

public static final int SELL
The value that parse() returns if the user enters 'sell' sell cargo at the current market.

See Also:
Constant Field Values

AVAILABLE

public static final int AVAILABLE
The value that parse() returns if the user enters 'available' to see what is available to buy at the current market.

See Also:
Constant Field Values

DO_NOT_UNDERSTAND

public static final int DO_NOT_UNDERSTAND
The value that parse() returns if it did not understand what the user entered.

See Also:
Constant Field Values

stdin

private static java.util.Scanner stdin
The Scanner object that is used by the various Parser methods

Constructor Detail

Parser

private Parser()
Making the constructor private prevents anybody from calling it (as we don't want to create objects of this class

Method Detail

getDestination

public static Location getDestination()
This method asks the user to enter the name of the location to travel to, having indicated that he/she wants to travel to a new location

Returns:
the Location to travel to.

getItemToTrade

public static int getItemToTrade(Inventory inventory,
                                 double marketCostFactor)
This method asks the user to enter the number corresponding to the items he/she wants to trade

Parameters:
inventory - the inventory of the current market,
marketCostFactor - double value indicating the market cost factor
Returns:
an int value indicating the items the user wishes to trade

parse

public static int parse()
This method reads in the user's input from the keyboard, and returns a value corresponding to what the user entered. The method only really looks at the first character entered, and ignores case. Thus, 'tunnel' and 'TIGER' will both return TRAVEL. The values returned are the fields listed above.

Returns:
An int value indicating what the user entered.