private static void DisplayResults(IGradeTracker book) { GradeBookStatistics stats = book.ComputeStatistics(); foreach (float grade in book) { Console.WriteLine(grade); } WriteResult("Average", stats.AverageGrade); WriteResult("Highest", (int)stats.HighestGrade); WriteResult("Lowest", stats.LowestGrade); WriteResult(stats.GradeDescription, stats.LetterGrade); }
public override GradeBookStatistics ComputeStatistics() { GradeBookStatistics stats = new GradeBookStatistics(); float sum = 0; foreach (float grade in grades) { stats.HighestGrade = Math.Max(grade, stats.HighestGrade); stats.LowestGrade = Math.Min(grade, stats.LowestGrade); sum += grade; } stats.AverageGrade = sum / grades.Count; return(stats); }
public GradeBookStatistics ComputeStatistics() { GradeBookStatistics stats = new GradeBookStatistics(); float sum = 0; stats.Highest = grades[0]; stats.Lowest = grades[0]; foreach (float g in grades) { sum += g; stats.Highest = Math.Max(g, stats.Highest); stats.Lowest = Math.Min(g, stats.Lowest); } stats.Average = sum / grades.Count; return(stats); }
private static void RunBookApp() { GradeBook book = new GradeBook(); // Events book.NameChanged += new NameChangedDelegate(OnNameChanged); book.NameChanged += new NameChangedDelegate(OnNameChanged2); book.NameChanged += OnNameChanged2; book.NameChanged += OnNameChanged2; book.NameChanged -= OnNameChanged2; /// Delegate Writer w = new Writer(WriteBookName); book.Name = "My book"; // Exception try { book.Name = ""; } catch (ArgumentNullException e) { Console.WriteLine(e.Message); } book.AddGrade(91); book.AddGrade(84.5f); GradeBookStatistics stat = book.ComputeStatistics(); w(book); //WriteBookName(book); WriteResult("Lowest Grade", stat.Lowest); WriteResult("Highest Grade", stat.Highest); WriteResult("Average Grade", stat.Average); WriteResult("LetterGrade", stat.LetterGrade); book.WriteGrades(Console.Out); // Exception using (StreamWriter sw = File.CreateText("grades.txt")) { book.WriteGrades(sw); sw.Close(); } }