/// <summary> /// Gets the maximum number of credit points worth of subjects that can run during a semester /// </summary> public int GetMaxCreditPoints(int year, Session session) { if (year <= 0) { throw new ArgumentException("Year must be positive"); } if (MaxCreditPoints.TryGetValue(new Time { year = year, session = session }, out int value)) { return(value); } return(GetMaxCreditPoints(year - 1, session)); }
/// <summary> /// Add more time to the plan /// </summary> public void AddYear() { int year = MaxCreditPoints.Any() ? 1 + MaxCreditPoints.Keys.Max(time => time.year) : 1; if (year == 1 || year > 20) { // Add a standard year MaxCreditPoints.Add(new Time { year = year, session = Session.S1 }, 40); MaxCreditPoints.Add(new Time { year = year, session = Session.WV }, 10); MaxCreditPoints.Add(new Time { year = year, session = Session.S2 }, 40); MaxCreditPoints.Add(new Time { year = year, session = Session.S3 }, 20); } else { // Copy the previous year MaxCreditPoints.Add(new Time { year = year, session = Session.S1 }, GetMaxCreditPoints(year - 1, Session.S1)); MaxCreditPoints.Add(new Time { year = year, session = Session.WV }, GetMaxCreditPoints(year - 1, Session.WV)); MaxCreditPoints.Add(new Time { year = year, session = Session.S2 }, GetMaxCreditPoints(year - 1, Session.S2)); MaxCreditPoints.Add(new Time { year = year, session = Session.S3 }, GetMaxCreditPoints(year - 1, Session.S3)); } if (year > 90) { throw new InvalidOperationException("Unless the user is a fool, this should not happen"); } }