private void AddAnimal() { Console.WriteLine("Which Animal it is?"); var animalName = Console.ReadLine(); Console.WriteLine($"What is the question that differentate {Value} and {animalName}"); var questionName = Console.ReadLine(); Console.WriteLine($"Is the answer to this question is yes or no for new animal: type y or n"); var answer = Console.ReadLine(); var question = new QuestionNode(questionName); var animal = new AnimalLeaf(animalName); if (answer.Equals("y", StringComparison.InvariantCultureIgnoreCase)) { question.YesQuestion = animal; question.NoQuestion = this; } else { question.YesQuestion = this; question.NoQuestion = animal; } animal.Parent = question; if (this == Parent.YesQuestion) { Parent.YesQuestion = question; } else { Parent.NoQuestion = question; } Parent = question; }
public QuestionNode GetNode() { var questionNode = new QuestionNode("Has a trunk, trumpets and is grey?"); var questionNode2 = new QuestionNode("Has a mane, roars and is yellow?"); var elephent = new AnimalLeaf("Elephent"); var lion = new AnimalLeaf("Lion"); var cat = new AnimalLeaf("Cat"); questionNode.YesQuestion = elephent; questionNode.NoQuestion = questionNode2; elephent.Parent = questionNode; questionNode2.Parent = questionNode; lion.Parent = questionNode2; cat.Parent = questionNode2; questionNode2.YesQuestion = lion; questionNode2.NoQuestion = cat; return(questionNode); }