responder.java

来自「现在在国外大学里最流行的java学习软件,同时还有大量的example,在名为p」· Java 代码 · 共 62 行

JAVA
62
字号
import java.util.ArrayList;import java.util.Random;/** * The responder class represents a response generator object. It is * used to generate an automatic response. * This is the second version of this class. This time, we generate  * some random behavior by randomly selecting a phrase from a predefined * list of responses. *  * @author     Michael Kolling and David J. Barnes * @version    0.2 */public class Responder{    private Random randomGenerator;    private ArrayList<String> responses;    /**     * Construct a Responder     */    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()    {        // Pick a random number for the index in the default response         // list. The number will be between 0 (inclusive) and the size        // of the list (exclusive).        int index = randomGenerator.nextInt(responses.size());        return responses.get(index);    }    /**     * Build up a list of default responses from which we can pick one     * if we don't know what else to say.     */    private void fillResponses()    {        responses.add("That sounds odd. Could you describe that problem in more detail?");        responses.add("No other customer has ever complained about this before. \n" +                      "What is your system configuration?");        responses.add("That sounds interesting. Tell me more...");        responses.add("I need a bit more information on that.");        responses.add("Have you checked that you do not have a dll conflict?");        responses.add("That is explained in the manual. Have you read the manual?");        responses.add("Your description is a bit wishy-washy. Have you got an expert\n" +                      "there with you who could describe this more precisely?");        responses.add("That's not a bug, it's a feature!");        responses.add("Could you elaborate on that?");    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?