static void Main(string[] args) { GradeBook book = new GradeBook(); book.AddGrade(91f); book.AddGrade(89.5f); book.AddGrade(75f); GradeStatistics stats = book.ComputeStatistics(); WriteBytes(stats.AverageGrade); Console.WriteLine(stats.AverageGrade); Console.WriteLine(stats.LowestGrade); Console.WriteLine(stats.HighestGrade); }
public override GradeStatistics ComputeStatistics() { Console.WriteLine("GradeBook::ComputeStatistics"); // return new GradeStatistics(); GradeStatistics stats = new GradeStatistics(); float sum = 0; foreach (float grade in grades) { stats.LowestGrade = Math.Min(grade, stats.LowestGrade); stats.HighestGrade = Math.Max(grade, stats.HighestGrade); sum += grade; } stats.AverageGrade = sum / grades.Count; return(stats); }
public GradeStatistics ComputeStatistics() { GradeStatistics stats = new GradeStatistics(); float sum = 0f; 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); }