Exemple #1
0
        static void Main(string[] args)
        {
            GradeBook book = new GradeBook(); //Instanciación

            book.AddGrade(91);
            book.AddGrade(88.5);
            book.AddGrade(87.5);

            GradeStaistics stats = book.ComputeStatistics();

            System.Console.WriteLine("Average: " + stats.AverageGrade);
            System.Console.WriteLine("Max: " + stats.HighestGrade);
            System.Console.WriteLine("Min: " + stats.LowestGrade);
        }
Exemple #2
0
        public GradeStaistics ComputeStatistics()
        {
            GradeStaistics stats = new GradeStaistics();

            double sum = 0;

            foreach (double 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);
        }