Advertisement
mnaufaldillah

Command Tugas 6

Nov 24th, 2020
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.86 KB | None | 0 0
  1. /**
  2.  * This class holds information about a command that
  3.  * was issued by the user.
  4.  * A command currently consists of two strings: a
  5.  * command word and a second  word (for example, if the command was "take map",
  6.  * then the two strings obviously are "take" and "map").
  7.  *
  8.  * The way this is used is: Commands are already
  9.  * checked for being valid  command words. If the user entered an invalid
  10.  * command (a word that is not known) then the command word is <null>.
  11.  *
  12.  *  If the command had only one word, then the second
  13.  *  word is <null>.
  14.  *  
  15.  * @author Muhammad Naufaldillah
  16.  * @version 24 November 2020
  17.  */
  18. public class Command
  19. {
  20.     private String commandWord;
  21.     private String secondWord;
  22.    
  23.     /**
  24.      * Create a command object. First and second word
  25.      * must be supplied, but either one (or both) can be null. The command
  26.      * word should be null to indicate that this was a command that is not
  27.      * recognised by this game.
  28.      */
  29.     public Command(String firstWord, String secondWord)
  30.     {
  31.         commandWord = firstWord;
  32.         this.secondWord = secondWord;
  33.     }
  34.    
  35.     /**
  36.      *  Return the command word (the first word) of this
  37.      *  command. If the command was not understood, the result is null.
  38.      */
  39.     public String getCommandWord()
  40.     {
  41.         return commandWord;
  42.     }
  43.    
  44.     /**
  45.      * Return the second word of this command. Returns
  46.      * null if there was no second word.
  47.      */
  48.     public String getSecondWord()
  49.     {
  50.         return secondWord;
  51.     }
  52.    
  53.     /**
  54.      * Return true if this command was not understood.
  55.      */
  56.     public boolean isUnknown()
  57.     {
  58.         return (commandWord == null);
  59.     }
  60.    
  61.     /**
  62.      * Return true if the command has a second word.
  63.      */
  64.     public boolean hasSecondWord()
  65.     {
  66.         return (secondWord != null);
  67.     }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement