protected override void Solve(out string answer) { Day currentDay = new Day(DayOfWeek.Monday); DateObject currentDate = new DateObject(1900, Month.January, 1); DateManipulator dateManipulator = new DateManipulator(currentDay, currentDate); while (!dateManipulator.Equals(1901, Month.January, 1)) { dateManipulator++; } int sundaysCount = 0; while (!dateManipulator.Equals(2000, Month.December, 31)) { dateManipulator++; if (dateManipulator.IsSundayOnFirstDayOfTheMonth()) { sundaysCount++; } } answer = string.Format("The number of Sundays that fell on the first of the month during the twentieth century (1 Jan 1901 to 31 Dec 2000) is {0}.", sundaysCount); }
public DateManipulator(Day dayOfWeek, DateObject date) { this.dayOfWeek = dayOfWeek; this.currentDate = date; }