public IBook CrackingTheCodingInterview(string filename) { // 1.1,3.2,14.1 var biggestChapterNumberSoFar = 0; var solvedQuestions = new HashSet <QuestionNumber>(); using (TextReader reader = File.OpenText(filename)) { var questions = reader.ReadLine().Split(','); foreach (var q in questions) { string[] question = q.Split('.'); var qn = new QuestionNumber(int.Parse(question[0]), int.Parse(question[1])); qn.Solved = true; if (!solvedQuestions.Contains(qn)) { solvedQuestions.Add(qn); biggestChapterNumberSoFar = Math.Max(biggestChapterNumberSoFar, qn.Chapter); } } } if (biggestChapterNumberSoFar < 1) { throw new InvalidOperationException("no questions were saved in file."); } IBook book = new BookFactory().CrackingTheCodingInterview(); foreach (var solvedQuestion in solvedQuestions) { book.SolveQuestion(solvedQuestion); } return(book); }
public void SolveQuestion(QuestionNumber questionNumber) { _chapters[questionNumber.Chapter - 1].SolveQuestion(questionNumber); }