vendredi 29 avril 2016

If Statement in Arguments

im currently coding a Chat-Bot, for his answers I made the method following method:

// Choose Randomly From Given Answers
public String chooseAnswer(String... strings){
    int i = (int) strings.length;
    int random = (int)(Math.random() * i); 
    return strings[random];
}

That works totally fine. Now the following problem occurs: If the bot doesnt understand what the user said, he displays a random question or statement, for example.

chooseAnswer("Sounds great", "Whats your favorite color?", "Whats your favorite food?", "Tell me something");

The User can now answer, for example what his favorite color is. If he answered that once, the bot should never choose the question about his color again.

I have a variable for that, that counts how many times the user said something about his favorite color, so that isnt the problem.

Now it would be great if something like that would work:

chooseAnswer("Sounds great", if(favorite_color_count == 0){"Whats your favorite color?"}, "Whats your favorite food?", "Tell me something");

This obviously doesnt work.

I think i need an if statement outisde, but there are so many cases, because I have about 50 standard questions, so i would have to make one for every case und thats like i dont know.. 50+49+48...+2+1?

Has someone an idea how to handle this?

Aucun commentaire:

Enregistrer un commentaire