ace

compiling Responder ACE

ace
Jan 23rd, 2010
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. import java.util.Random;
  2. import java.util.ArrayList;
  3.  
  4.  
  5. /**
  6. * The responder class represents a response generator object.
  7. * It is used to generate an automatic response.
  8. *
  9. * @author Michael Kolling and David J. Barnes
  10. * @version 0.1
  11. */
  12. public class Responder
  13. {
  14. /**
  15. * Construct a Responder - nothing to do
  16. */
  17.  
  18. Random randomGenerator;
  19. private ArrayList<String> responses;
  20.  
  21. public Responder(){
  22. randomGenerator = new Random();
  23. responses = new ArrayList<String>();
  24. fillResponses();
  25. }
  26.  
  27. /**
  28. * Generate a response.
  29. * @return A string that should be displayed as the response
  30. */
  31. public String generateResponse()
  32. {
  33. return "That sounds interesting. Tell me more...";
  34. }
  35.  
  36. public String GetResponse()
  37. {
  38. int index = randomGenerator.nextInt(3);
  39. {
  40. return responses.get(index);
  41. }
  42. }
  43.  
  44. public void createResponses(String response)
  45. {
  46. responses.add(response);
  47. }
  48.  
  49. private void fillResponses()
  50. {
  51. createResponses("yes");
  52. createResponses("no");
  53. createResponses("maybe");
  54. }
  55.  
  56. }
Add Comment
Please, Sign In to add comment