public GradeStatistics ComputeStatistics()
        {
            GradeStatistics stats = new GradeStatistics();


            float sum = 0f;

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

            stats.AverageGrade = sum / grades.Count;



            return(stats);
        }
Пример #2
0
        static void Main()
        {
            GradeBook book = new GradeBook("roko pazymiuknyga");

            //book.AddGrades(99f);
            //book.AddGrades(89.5f);
            //book.AddGrades(69.1f);
            //book.AddGrades(75f);
            //book.AddGrades(44.5f);
            //book.AddGrades(29.4f);

            try
            {
                string[] lines = File.ReadAllLines("rades.txt");

                foreach (string line in lines)
                {
                    book.AddGrades(float.Parse(line));
                }
            }
            catch (FileNotFoundException ex)
            {
                Console.WriteLine("file is not located!");
                return;
            }
            catch (UnauthorizedAccessException ex)
            {
                Console.WriteLine("No access!");
            }

            book.WriteGrades(Console.Out);

            GradeStatistics stats = book.ComputeStatistics();

            Console.WriteLine(stats.AverageGrade);
            Console.WriteLine(stats.LowestGrade);
            Console.WriteLine(stats.BiggestGrade);
            Console.WriteLine("your grade is {0} which is {1} ", stats.LetterGrade, stats.GradeDescription);

            book.Name = "labas";
            WriteNames(book.Name);

            book.NameChanged += OnNameChange;

            bool x;

            do
            {
                try
                {
                    Console.WriteLine("Enter the book nsme");
                    book.Name = Console.ReadLine();
                    x         = false;
                }
                catch (ArgumentException ex)
                {
                    Console.WriteLine("Invalid name!");
                    x = true;
                }
            } while (x);



            //int number = 45;
            //WriteBytes(number);
            //WriteBytes(stats.AverageGrade);
        }