Esempio n. 1
0
        static void Main(string[] args)
        {
            GradeBook book = new GradeBook();

            book.AddGrade(91f);
            book.AddGrade(89.1f);
            book.AddGrade(75f);

            GradeStatistics stats = book.ComputeStatistics();


            Console.WriteLine(stats.AverageGrade);
            Console.WriteLine(stats.HighestGrade);
            Console.WriteLine(stats.LowestGrade);
            Console.WriteLine(stats.LetterGrade);
            Console.ReadLine();
        }
        public GradeStatistics ComputeStatistics()
        {
            GradeStatistics stats = new GradeStatistics();

            stats.HighestGrade = 0;
            float sum = 0f;


            foreach (float grade in grades)
            {
                stats.HighestGrade = Math.Max(grade, stats.HighestGrade);
                stats.LowestGrade  = Math.Min(grade, stats.LowestGrade);
                sum += grade;
            }

            if (grades.Count != 0)
            {
                stats.AverageGrade = sum / grades.Count;
            }

            return(stats);
        }