/** * <summary>This method stores a valid AcademicYear object into the School object.</summary> * * <param name="y">AcademicYear object to be added to the school.</param> * * <example> * <code>School sl = new School("Nottingham Secondary", 13); * sl.AddYear(12);</code> * Year 12 has been added to 'sl'.</example> */ public void AddYear(AcademicYear y) { if (y != null) { // Throws an exception if the year already exists within the School object GetYears.ForEach(_ => { if (_.GetYearNo == y.GetYearNo) { throw new ArgumentException("Year already exists!"); } }); GetYears.Add(y); } }
/** * <summary>This method retrieves the AcademicYear object which is equal to 'yearNo'.</summary> * * <param name="yearNo"></param> * * <example> * <code>School sl = new School("Midwest College", 9, 11); * sl.AddYears(12, 13);</code> * sl.GetYearByNo(13); * Year 13 will be returned.</example> * * <returns>Returns the year with the matching year number specifed by the 'yearNo' parameter.</returns> */ public AcademicYear GetYearByNo(int yearNo) { AcademicYear ay = null; GetYears.ForEach(year => { if (year.GetYearNo == yearNo) { ay = year; } }); if (ay == null) { // Throws an exception if 'ay' is still equal to null. throw new ArgumentException("Year does not exist!"); } return(ay); }