Advertisement
raffi_pratama

Untitled

Nov 16th, 2020
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.06 KB | None | 0 0
  1. /**  
  2.  *
  3.  * Class ini mengadakan enumerasi pada semua kata perintah yang dikenal dalam game.
  4.  * Ini digunakan untuk mengenali command saat diketik..
  5.  *
  6.  * @author  M.Rayhan Raffi P.
  7.  
  8.  * @version 16-11-2020
  9.  */
  10.  
  11. public class CommandWords
  12.  
  13. {
  14.  
  15.     // a constant array that holds all valid command words
  16.  
  17.     private static final String[] validCommands = {
  18.  
  19.         "go", "quit", "help"
  20.  
  21.     };
  22.  
  23.  
  24.  
  25.     /**
  26.  
  27.      * Constructor - initialise the command words.
  28.  
  29.      */
  30.  
  31.     public CommandWords()
  32.  
  33.     {
  34.  
  35.         // nothing to do at the moment...
  36.  
  37.     }
  38.  
  39.  
  40.  
  41.     /**
  42.  
  43.      * Check whether a given String is a valid command word.
  44.  
  45.      * @return true if a given string is a valid command,
  46.  
  47.      * false if it isn't.
  48.  
  49.      */
  50.  
  51.     public boolean isCommand(String aString)
  52.  
  53.     {
  54.  
  55.         for(int i = 0; i < validCommands.length; i++) {
  56.  
  57.             if(validCommands[i].equals(aString))
  58.  
  59.                 return true;
  60.  
  61.         }
  62.  
  63.         // if we get here, the string was not found in the commands
  64.  
  65.         return false;
  66.  
  67.     }
  68.  
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement