I wrote out a list filled with answers for a question. I want to use my GetAnswer() method to return the current answer as a string.
The issue that I'm having is that I can't get the random answer that I selected to print out.
namespace Magic8Ball_Logic
{
public class Magic8Ball
{
private List<string> _answers;
private int _currentIndex;
public Magic8Ball()
{
_answers = new List<string>();
_answers.Add("It is certain.");
_answers.Add("It is decidedly so.");
_answers.Add("Without a doubt.");
}
public Magic8Ball(List<string> answers)
{
//I won't use the default. Use the ones passed in.
_answers = answers;
}
public void Shake()
{
//picking the index of the answer to show the user
Random r = new Random();
int index = r.Next(_answers.Count);
string randomString = _answers[index];
}
public string GetAnswer()
{
//using the index picked by shake to return the answer
return randomString;
}