Difference between revisions of "Parser class assignment"

From WLCS
(New page: == Objective == * You will learn to create a static class comprised of static variables and methods == Purpose == * The Parser class allows you to use its internal static methods to obtai...)
 
Line 3: Line 3:
  
 
== Purpose ==
 
== Purpose ==
* The Parser class allows you to use its internal static methods to obtain input commands for your game
+
* The Parser class allows you to use its internal static methods to obtain input commands for your game
  
 
== Attributes ==
 
== Attributes ==
 +
All methods and variables in the Parser method should be declared static.  Note that this means there will never be a need to create a Parser object (i.e., an instance of the Parser class) because all methods and constants can be access as Parser.parse(), Parser.NORTH, etc.
  
 +
The Parser class should provide the following integer constants, each representing a possible command that the user might type.  These are class variables (a.k.a. class fields).
 +
 +
'''
 +
* NORTH
 +
* EAST
 +
* SOUTH
 +
* WEST
 +
* ATTACK
 +
* LOOK
 +
* GET
 +
* QUIT
 +
* DO_NOT_UNDERSTAND
 +
'''
 +
 +
The first one (NORTH) needs to have integer value 1, the second has 2, etc. (thus, QUIT has value 8).  Each of the constants should be public final static.  For example, the first one is defined as:
 +
 +
<source lang="java">
 +
public static final int NORTH = 1;
 +
</source>
 +
 +
Note that the last constant (DO_NOT_UNDERSTAND) has value -1, not value 9.  Also, the parser should also define a Scanner object as follows:
  
 
== Methods ==
 
== Methods ==
 +
 +
 +
== Testing ==

Revision as of 10:00, 27 April 2010

Objective

  • You will learn to create a static class comprised of static variables and methods

Purpose

  • The Parser class allows you to use its internal static methods to obtain input commands for your game.

Attributes

All methods and variables in the Parser method should be declared static. Note that this means there will never be a need to create a Parser object (i.e., an instance of the Parser class) because all methods and constants can be access as Parser.parse(), Parser.NORTH, etc.

The Parser class should provide the following integer constants, each representing a possible command that the user might type. These are class variables (a.k.a. class fields).

  • NORTH
  • EAST
  • SOUTH
  • WEST
  • ATTACK
  • LOOK
  • GET
  • QUIT
  • DO_NOT_UNDERSTAND

The first one (NORTH) needs to have integer value 1, the second has 2, etc. (thus, QUIT has value 8). Each of the constants should be public final static. For example, the first one is defined as:

public static final int NORTH = 1;

Note that the last constant (DO_NOT_UNDERSTAND) has value -1, not value 9. Also, the parser should also define a Scanner object as follows:

Methods

Testing