I have a program that emulates a small translation program and I'm trying to figure out how would I go about making the error responses not repeat itself twice in a row (e.g the response "I don't know this word, sorry." can be explicitly stated right after when there is a failure to translate a word).
public void fillErrorResponses() {
// Adding responses to be used if no translation was found.
errorResponses.add("I am sorry but I do not know how to translate this.");
errorResponses.add("I don't know this word, sorry.");
errorResponses.add("Are you sure that this is a word?");
errorResponses.add("This cannot be translated.");
}
public String getErrorResponse() {
// Pick a random number for the index in the error response list.
// The number will be between 0 (inclusive) and the size of the list (exclusive).
int idx = rnd.nextInt(errorResponses.size());
return errorResponses.get(idx);
At the moment, when a word that a user inputs cannot be translated, it will provide a random error response but still allows for that same error response to be displayed directly after it being used, for example:
Please, type in a single word to translate it.
> gah
I don't know this word, sorry.
> gah
I am sorry but I do not know how to translate this.
> gah
I am sorry but I do not know how to translate this.
How do i make it so that it doesn't show the same response twice in a row when a user inputs word that cannot be translated?
Aucun commentaire:
Enregistrer un commentaire