Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Random;
- import java.util.ArrayList;
- /**
- * The responder class represents a response generator object.
- * It is used to generate an automatic response.
- *
- * @author Michael Kolling and David J. Barnes
- * @version 0.1
- */
- public class Responder
- {
- /**
- * Construct a Responder - nothing to do
- */
- Random randomGenerator;
- private ArrayList<String> responses;
- public Responder(){
- randomGenerator = new Random();
- responses = new ArrayList<String>();
- fillResponses();
- }
- /**
- * Generate a response.
- * @return A string that should be displayed as the response
- */
- public String generateResponse()
- {
- return "That sounds interesting. Tell me more...";
- }
- public String GetResponse()
- {
- int index = randomGenerator.nextInt(3);
- {
- return responses.get(index);
- }
- }
- public void createResponses(String response)
- {
- responses.add(response);
- }
- private void fillResponses()
- {
- createResponses("yes");
- createResponses("no");
- createResponses("maybe");
- }
- }
Add Comment
Please, Sign In to add comment