Difference between revisions of "Parser class assignment"

From WLCS
Line 10: Line 10:
 
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).
 
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 = 1
* NORTH
+
* EAST = 2
* EAST
+
* SOUTH = 3
* SOUTH
+
* WEST = 4
* WEST
+
* ATTACK = 5
* ATTACK
+
* LOOK = 6
* LOOK
+
* GET = 7
* GET
+
* QUIT = 8
* QUIT
+
* DO_NOT_UNDERSTAND = -1
* 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:
 
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:
Line 28: Line 26:
 
</source>
 
</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:
+
'''Note''' that the last constant (DO_NOT_UNDERSTAND) has value -1, not value 9.   
  
 
== Methods ==
 
== Methods ==
 +
  
  
 
== Testing ==
 
== Testing ==

Revision as of 10:02, 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 = 1
  • EAST = 2
  • SOUTH = 3
  • WEST = 4
  • ATTACK = 5
  • LOOK = 6
  • GET = 7
  • QUIT = 8
  • DO_NOT_UNDERSTAND = -1

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.

Methods

Testing