public override GradeStatistics ComputeStatistics() { Console.WriteLine("GradeBook::ComputeStatistics"); GradeStatistics stats = new GradeStatistics(); float sum = 0; foreach (float grade in grades) { //stats.AverageGrade = sum / grades.Count; stats.HighestGrade = Math.Max(grade, stats.HighestGrade); stats.LowestGrade = Math.Min(grade, stats.LowestGrade); sum += grade; } stats.AverageGrade = sum / grades.Count; return(stats); }
static void Main(string[] args) { //SpeechSynthesizer synth = new SpeechSynthesizer(); //synth.Speak("Hello! This is the gradebook program"); //GradeBook book = new GradeBook(); GradeBook book = new ThrowAwayGradeBook(); // this is legal since its a type GetBookName(book); //book.Name = "Scott's Grade Book"; // if field is public //book.Name = null; // property ignores this Console.WriteLine(book.Name); AddingGrades(book); StreamWriter outputFile = File.CreateText("gradesz.txt"); book.WriteGrades(outputFile); outputFile.Close(); // this never created the text GradeStatistics stats = book.ComputeStatistics(); WriteResult("Average", stats.AverageGrade); WriteResult("Highest", (int)stats.HighestGrade); WriteResult("Lowest", stats.LowestGrade); WriteResult(stats.Description, stats.LetterGrade); }