public void AddGrade(double grade) { if (grade < 0 || grade > 100) { throw new ArgumentException("Grades must be between 0 and 100"); } Grades.Add(grade); }
public override void AddGrade(double grade) { if (grade <= 100 && grade >= 0) { Grades.Add(grade); if (GradeAdded != null) { GradeAdded(this, new EventArgs()); } } else { throw new ArgumentException($"Invalid {nameof(grade)}"); } }
public override void AddGrade <T>(T newGrade) { try { double tempGrade = Convert.ToDouble(newGrade); if (GradeGood(tempGrade)) { Grades.Add(tempGrade); } } catch (InvalidCastException ex) { if (newGrade.GetType() == typeof(char)) { AddLetterGrade(Convert.ToChar(newGrade)); } else { Console.WriteLine(ex.Message); } } catch (ArgumentException ex) { Console.WriteLine(ex.Message); } catch (FormatException ex) { Console.WriteLine(ex.Message); } catch (Exception ex) { Console.WriteLine($"Argument {newGrade} caused and exception: {ex.Message}"); throw ex; } finally { if (GradeAdded != null) { GradeAdded(this, new EventArgs()); } Console.WriteLine("Thank you for typing."); } }