naufalphew

command

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