Advertisement
raffi_pratama

Untitled

Nov 16th, 2020
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.00 KB | None | 0 0
  1. /**
  2.  * Class ini menyimpan informasi tentang command yang dikeluarkan oleh pengguna.
  3.  * A command dari  dua string: kata command dan kata kedua
  4.  * (contoh, jika command adalah "take map", maka dua string itu
  5.  * adalah "take" dan "map").
  6.  *
  7.  * Cara penggunaannya adalah: Commands udah diperiksa untuk menjadi
  8.  * kata command yang valid. Jika pengguna memasukkan command yang tidak valid
  9.  * (kata yang tidak dikenal) maka kata command word adalah <null>.
  10.  *
  11.  * Jika command hanya punya satu kata, maka kata keduanya <null>.
  12.  *
  13.  * @author  M. Rayhan Raffi P.
  14.  * @version 16-11-2020
  15.  */
  16.  
  17.  
  18.  
  19. public class Command
  20.  
  21. {
  22.  
  23.     private String commandWord;
  24.  
  25.     private String secondWord;
  26.  
  27.  
  28.  
  29.     /**
  30.  
  31.      * Create a command object. First and second word must be supplied, but
  32.  
  33.      * either one (or both) can be null.
  34.  
  35.      * @param firstWord The first word of the command. Null if the command
  36.  
  37.      *                  was not recognised.
  38.  
  39.      * @param secondWord The second word of the command.
  40.  
  41.      */
  42.  
  43.     public Command(String firstWord, String secondWord)
  44.  
  45.     {
  46.  
  47.         commandWord = firstWord;
  48.  
  49.         this.secondWord = secondWord;
  50.  
  51.     }
  52.  
  53.  
  54.  
  55.     /**
  56.  
  57.      * Return the command word (the first word) of this command. If the
  58.  
  59.      * command was not understood, the result is null.
  60.  
  61.      * @return The command word.
  62.  
  63.      */
  64.  
  65.     public String getCommandWord()
  66.  
  67.     {
  68.  
  69.         return commandWord;
  70.  
  71.     }
  72.  
  73.  
  74.  
  75.     /**
  76.  
  77.      * @return The second word of this command. Returns null if there was no
  78.  
  79.      * second word.
  80.  
  81.      */
  82.  
  83.     public String getSecondWord()
  84.  
  85.     {
  86.  
  87.         return secondWord;
  88.  
  89.     }
  90.  
  91.  
  92.  
  93.     /**
  94.  
  95.      * @return true if this command was not understood.
  96.  
  97.      */
  98.  
  99.     public boolean isUnknown()
  100.  
  101.     {
  102.  
  103.         return (commandWord == null);
  104.  
  105.     }
  106.  
  107.  
  108.  
  109.     /**
  110.  
  111.      * @return true if the command has a second word.
  112.  
  113.      */
  114.  
  115.     public boolean hasSecondWord()
  116.  
  117.     {
  118.  
  119.         return (secondWord != null);
  120.  
  121.     }
  122.  
  123. }
  124.  
  125.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement