Pastebin launched a little side project called HostCabi.net, check it out ;-)Don't like ads? PRO users don't see any ads ;-)
Guest

compiling Responder ACE

By: ace on Jan 23rd, 2010  |  syntax: None  |  size: 1.21 KB  |  hits: 17  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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. }