Ejemplo n.º 1
0
        private static void WriteResults(IGradeTracker book)
        {
            var stats = book.ComputeStatistics();

            WriteResult("Average", stats.AverageGrade);
            WriteResult("Highest", stats.HighestGrade);
            WriteResult("Lowest", stats.LowestGrade);
            WriteResult(stats.Description, stats.LetterGrade);
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            IGradeTracker book = CreateGradeBook();

            AddGrades(book);
            // book.WriteGrades(Console.Out);

            GradeStatistics stats = book.ComputeStatistics();

            WriteResult("Average", stats.AverageGrade);
            WriteResult("Highest", stats.HighestGrade);
            WriteResult("Lowest ", stats.LowestGrade);
            WriteResult("Grade", stats.LetterGrade);
        }
        private static void WriteResults(IGradeTracker book)
        {
            GradeStatistics stats = book.ComputeStatistics();

            Console.WriteLine("All grades:");
            foreach (float grade in book)
            {
                Console.WriteLine(grade);
            }
            Console.WriteLine("---\nStatistics:");
            Console.WriteLine($"Highest: {stats.AverageGrade}");
            Console.WriteLine($"Lowest: {stats.LowestGrade}");
            Console.WriteLine($"Average: {stats.HighestGrade}");
        }
Ejemplo n.º 4
0
        private static void WriteResults(IGradeTracker book)
        {
            GradeStatistics stats = book.ComputeStatistics(); //Runs ComputerStatistics and places the values at the memory locations for the fields in the object stats.

            foreach (float grade in book)
            {
                Console.WriteLine(grade);
            }

            WriteResult("Average", stats.AverageGrade);
            WriteResult("Max Grade", (int)stats.HighestGrade); //Type coercion/conversion from float to int
            WriteResult("Min Grade", (int)stats.LowestGrade);  //Type coercion/conversion from float to int
            WriteResult(stats.LetterGrade, stats.Description);
        }
        private static void WriteResults(IGradeTracker book)
        {
            GradeStatistics stats = book.ComputeStatistics();

            foreach (float grade in book)
            {
                Console.WriteLine(grade);
            }

            WriteResult("Average", stats.AverageGrade);
            WriteResult("Highest", stats.HighestGrade);
            WriteResult("Lowest", stats.LowestGrade);
            WriteResult(stats.Description, stats.LetterGrade);
        }
Ejemplo n.º 6
0
        private static void WriteResults(IGradeTracker book)
        {
            GradeStatistics stats = book.ComputeStatistics();

            foreach (float grade in book)
            {
                Console.WriteLine(grade);
            }

            WriteResult("Average", stats.AverageGrade);
            WriteResult("Highest", stats.HighestGrade);
            WriteResult("Lowest", stats.LowestGrade);
            WriteResult(stats.Description, stats.LetterGrade);
        }
Ejemplo n.º 7
0
        private static void WriteResults(IGradeTracker book)
        {
            Console.WriteLine("All the Grades");
            GradeStatistics stats = book.ComputeStatistics();

            foreach (var grade in book)
            {
                Console.WriteLine(grade);
            }
            Console.WriteLine("-----------------------------");
            WriteResult("Max val", stats.HightestGrade);
            WriteResult("Min val", (int)stats.LowestGrade);
            WriteResult("Average val", stats.AverageGrade);
            WriteResult("Letter description", stats.Description, stats.LetterGrade);
        }
Ejemplo n.º 8
0
        private static void WriteResults(IGradeTracker book)
        {
            GradeStatistics stats = book.ComputeStatistics();

            Console.WriteLine(book.Name);
            //allowed by inheriting enumerable in igradetracker
            foreach (float grade in book)
            {
                Console.WriteLine(grade);
            }
            WriteResult("Average Grade", stats.AverageGrade);
            WriteResult("Highest Grade", stats.HighestGrade);
            WriteResult("Lowest Grade", stats.LowestGrade);
            WriteResult(stats.Description, stats.LetterGrade);
        }
Ejemplo n.º 9
0
        private static void WriteResults(IGradeTracker book)
        {
            GradeStatistics stats = book.ComputeStatistics();

            foreach (float grade in book)
            {
                Console.WriteLine(grade);
            }

            //Console.WriteLine(book.Name);
            WriteResult("Average", stats.AverageGrade);
            WriteResult("Highest grade", (int)stats.HighestGrade);
            WriteResult("Lowest grade", stats.LowestGrade);
            WriteResult("Grade", stats.LetterGrade);
        }
Ejemplo n.º 10
0
        private static void WriteResults(IGradeTracker book)
        {
            GradeStatistics stats = book.ComputeStatistics();

            //foreach (float grade in book)
            //{
            //    Console.WriteLine(grade);
            //}

            Console.WriteLine($"GradeBook:\t{book.Name}");
            WriteResult("Average\t", stats.AverageGrade);
            WriteResult("Highest\t", stats.HighestGrade);
            WriteResult("Lowest\t", stats.LowestGrade);
            WriteResult("Grade\t", stats.LetterGrade, stats.Description);
        }
Ejemplo n.º 11
0
        private static void WriteGrades(IGradeTracker book)
        {
            GradeStatistics stats = book.ComputeStatistics();

            foreach (float grade in book)
            {
                Console.WriteLine(grade);
            }

            //Console.WriteLine(book.Name);
            WriteResult("Average", stats.averageGrade);
            WriteResult("Highest", (int)stats.highestGrade);
            WriteResult("Lowest", stats.lowestGrade);
            WriteResult(stats.Description, stats.Letter);
        }
Ejemplo n.º 12
0
        private static void WriteGrades(IGradeTracker gradeBook)
        {
            GradeStatistics gradeStatistics = gradeBook.ComputeStatistics();

            // Only possible when implementing the IEnumerable interface
            foreach (float grade in gradeBook)
            {
                Console.WriteLine(grade);
            }

            WriteResult("Highest", gradeStatistics.HighestGrade);
            WriteResult("Lowest", gradeStatistics.LowestGrade);
            WriteResult("Average", gradeStatistics.AverageGrade);
            WriteResult(gradeStatistics.LetterGrade, gradeStatistics.Description);
        }
Ejemplo n.º 13
0
        private static void WriteResults(IGradeTracker book)
        {
            GradeStatistics stats = book.ComputeStatistics();

            // can now use foreach because IGradeTracker inherits from IEnumerable
            foreach (var grade in book)
            {
                Console.WriteLine(grade);
            }

            WriteResult("Average", stats.AverageGrade);
            // C# type cast (int) to change to int value
            WriteResult("Highest", stats.HighestGrade);
            WriteResult("Lowest", stats.LowestGrade);
            WriteResult(stats.Description, stats.LetterGrade);
        }
Ejemplo n.º 14
0
        static void WriteResults(IGradeTracker book)
        {
            // Because GradeBook.ComputeStatistics has virtual keyword anything that inherits this can override it.
            // We created a new ThrowAwayGradeBook object named book and called book.ComputeStatistics.
            // Since ThrowAwayGradeBook.ComputeStatistics uses the override keyword we can override the virtual
            // method of the GradeBook and call the method we really want.
            GradeStatistics stats = book.ComputeStatistics();

            foreach (float grade in book)
            {
                Console.WriteLine(grade);
            }
            WriteResult("Average", stats.AverageGrade);
            WriteResult("Highest", stats.HighestGrade);
            WriteResult("Lowest", stats.LowestGrade);
            WriteResult(stats.Description, stats.LetterGrade);
        }
Ejemplo n.º 15
0
        private static void WriteResults(IGradeTracker book)
        {
            GradeStatistics stats = book.ComputeStatistics();

            foreach (float grade in book)
            {
                Console.WriteLine(grade);
            }


            Console.WriteLine(stats.AverageGrade);
            Console.WriteLine(stats.HighestGrade);
            Console.WriteLine(stats.LowestGrade);
            Console.WriteLine(book.Name);
            book.Name = "EutoMonitorInternational";
            Console.ReadLine();
        }
Ejemplo n.º 16
0
        private static void WriteResults(IGradeTracker book1)
        {
            GradeStatistics book1stats = book1.ComputeStatistics();

            foreach (float grade in book1)
            {
                Console.WriteLine(grade);
            }


            WriteResult("Name", book1.Name);
            WriteResult("Average", book1stats.AverageGrade);
            WriteResult("Highest Grade", book1stats.HighestGrade);
            WriteResult("Lowest Grade", book1stats.LowestGrade);
            WriteResult("Grade", book1stats.LetterGrade);
            WriteResult("Description", book1stats.Description);
        }
Ejemplo n.º 17
0
        private static void WriteAllResults(IGradeTracker book)
        {
            //computing stats on the gradebook
            GradeStatistics stats = book.ComputeStatistics();

            Console.WriteLine("\n");

            foreach (float grade in book)
            {
                Console.WriteLine(grade);
            }

            WriteResults("This is the average grade: ", stats.AverageGrade);
            WriteResults("This is the highest grade: ", stats.HighestGrade);
            WriteResults("This is the lowest grade: ", stats.LowestGrade);
            WriteResults(stats.Description, stats.LetterGrade);
        }
Ejemplo n.º 18
0
        private static void WriteResults(IGradeTracker book)
        {
            GradeStatistics stats = book.ComputeStatistics();

            foreach (float grade in book)
            {
                Console.WriteLine(grade);
            }

            // cw tab tab for console.writeLine();
            //Console.WriteLine(book.Name);
            WriteResult("Average", stats.AverageGrade);
            WriteResult("Highest", stats.HighestGrade);
            WriteResult("Lowest", stats.LowestGrade);
            //WriteResult("Params Example", stats.LowestGrade, 2, 3, 4);
            WriteResult(stats.Description, stats.LetterGrade);
        }
Ejemplo n.º 19
0
        private static void WriteResults(IGradeTracker book)
        {
            //Instantiate GradeStatistics object
            GradeStatistics stats = book.ComputeStatistics();

            foreach (float grade in book) //polymorphism example using IEnumerator
            {
                Console.WriteLine(grade);
            }

            //Write grades to console
            book.WriteGrades(Console.Out);

            WriteResult("Average", stats.AverageGrade);
            WriteResult("Highest", stats.HighestGrade);
            WriteResult("Lowest", stats.LowestGrade);
            WriteResult(stats.Description, stats.LetterGrade);
        }
Ejemplo n.º 20
0
        static void Main(string[] args)
        {
            SpeechSynthesizer synth = new SpeechSynthesizer();

            synth.Speak("Hello!, this is the grade book program");
            IGradeTracker book = CreateGradeBook();

            // book.NameChanged = new NameChangedDelegate(OnNameChanged);
            //book.NameChanged = new NameChangedDelegate(OnNameChanged2);
            book.NameChanged += new NameChangedDelegate(OnNameChanged);
            // book.NameChanged += new NameChangedDelegate(OnNameChanged2);
            //book.NameChanged = null;


            try
            {
                Console.WriteLine("Enter a name");
                book.Name = Console.ReadLine();
            }
            catch (ArgumentException ex)
            {
                Console.WriteLine(ex.Message);
            }


            //book.Name = "Kumar's Grade Book";
            //book.Name = "Kumar' Grade Book";

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

            book.WriteGrades(Console.Out);

            GradeStatistics stats = book.ComputeStatistics();

            ////book.LowestGrade();

            WriteResult("Average", stats.AverageGrade);
            WriteResult("Highest Grade", (int)stats.HighestGrade);
            WriteResult("Lowest Grade", stats.LowestGrade);
            WriteResult(stats.Description, stats.LetterGrade);
            Console.ReadLine();
        }
Ejemplo n.º 21
0
        private static void WriteResults(IGradeTracker book)
        //private static void WriteResults(GradeBook book)
        //private static void WriteResults(ThrowAwayGradeBook book)
        {
            GradeStatistics stats = book.ComputeStatistics();

            foreach (float grade in book)
            {
                Console.WriteLine(grade);
            }
            // Console.WriteLine(book.Name);

            WriteResult("Average", stats.AverageGrade);
            WriteResult("Highest", (int)stats.HighestGrade); // (int) is type conversion from float to int
            WriteResult("Highest", stats.HighestGrade);
            WriteResult("Lowest", stats.LowestGrade);
            //WriteResult("Grade", stats.LetterGrade);
            WriteResult(stats.Description, stats.LetterGrade);
        }
Ejemplo n.º 22
0
        static void Main(string[] args)
        {
            IGradeTracker book = CreateGradeBook();

            GetBookName(book);
            WriteResults(book);

            using (StreamWriter outputfile = File.CreateText("grades.txt"))
            {
                book.WriteGrades(outputfile);
            }

            GradeStatistics stats = book.ComputeStatistics();

            Console.WriteLine(book.Name);
            WriteResult("Highest,", stats.HighestGrade);
            WriteResult("Lowest,", stats.LowestGrade);
            WriteResult("Average,", stats.AverageGrade);
            WriteResult(stats.Description, stats.LetterGrade);
        }
Ejemplo n.º 23
0
        private static void WriteResults(IGradeTracker book)
        {
            //Display the grades in a console
            Console.WriteLine("________________________________");
            Console.WriteLine("The grades you've entered are:");
            foreach (float grade in book)
            {
                Console.WriteLine(grade);
            }
            Console.WriteLine("________________________________");

            //Display the statistics
            Console.WriteLine("The statistics  for the grades are:");
            GradeStatistics stats = book.ComputeStatistics();

            WriteLine("Highest Grade", stats.HighestGrade);
            WriteLine("Lowest Grade", stats.LowestGrade);
            WriteLine("The Average Grade", stats.AverageGrade);
            WriteLine(stats.Description, stats.LetterGrade);
        }
Ejemplo n.º 24
0
        private static void WriteResults(IGradeTracker book1)
        {
            try
            {
                GradeStatistics stats = book1.ComputeStatistics();

                foreach (GradeBook grade in book1)
                {
                    Console.WriteLine(grade);
                }

                WriteResults("Average", stats.AverageGrade);
                WriteResults("Highest", stats.HighestGrade);
                WriteResults("Lowest", stats.LowestGrade);
                WriteResults(stats.Description, stats.LetterGrade);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
Ejemplo n.º 25
0
        private static void WriteResults(IGradeTracker book)
        {
            GradeStatistics stats = book.ComputeStatistics();

            foreach (float grade in book)
            {
                Console.WriteLine(grade);
            }

            //synth.Speak(nameof(stats.AverageGrade ) + " " + stats.AverageGrade);
            //synth.Speak(nameof(stats.HighestGrade) + " " + stats.HighestGrade);
            //synth.Speak(nameof(stats.LowestGrade) + " " + stats.LowestGrade);

            //Console.WriteLine(nameof(stats.AverageGrade) + " " + stats.AverageGrade);
            //Console.WriteLine(nameof(stats.HighestGrade) + " " + stats.HighestGrade);
            //Console.WriteLine(nameof(stats.LowestGrade) + " " + stats.LowestGrade);
            Console.WriteLine(book.Name);
            WriteResult("Average", stats.AverageGrade);
            WriteResult("HighestGrade", (int)stats.HighestGrade);
            WriteResult("LowestGrade", stats.LowestGrade);
            WriteResult(stats.Description, stats.LetterGrade);
        }
Ejemplo n.º 26
0
        static void Main(string[] args)
        {
            IGradeTracker book = CreateGradeBook();

            //GetBookName(book);
            SaveGrades(book);
            WriteResults(book);

            GradeStatistics stats = book.ComputeStatistics();

            foreach (float grade in book)
            {
                Console.WriteLine(grade);
            }


            WriteResult("Average", stats.AverageGrade);
            WriteResult("Highest", stats.HighestGrade);
            WriteResult("Lowest", stats.LowestGrade);
            WriteResult("Grade", stats.LetterGrade);
            WriteResult(stats.Description, stats.LetterGrade);
        }
Ejemplo n.º 27
0
        private static void Main(string[] args)
        {
            IGradeTracker book = CreateGradeBook();

            //book.NameChanged += OnNameChanged;

            Console.WriteLine("Enter a name:");
            try {
                //book.Name = Console.ReadLine();
            } catch (ArgumentException ex) {
                Console.WriteLine(ex.Message);
                //book.Name = "Empty";
            } finally {
            }
            AddGrades(book);

            GradeStatistics stats = book.ComputeStatistics();

            Console.WriteLine(book.Name);
            WriteResult("Average", stats.AverageGrade);
            WriteResult("Highest", (int)stats.AverageGrade);
            WriteResult("Lowest", stats.LowestGrade);
            WriteResult(stats.Description, stats.LetterGrade);
        }
Ejemplo n.º 28
0
        //static void GiveBookAName(GradeBook book)
        //{
        //    book = new GradeBook();
        //    book.Name = "The New gradebook";
        //}

        //static void IncrementNumber(int number)
        //{
        //    number += 1;
        //}

        static void Main(string[] args)
        {
            //SpeechSynthesizer speech = new SpeechSynthesizer();
            //speech.Speak("Hello world");

            //Arrays();
            //Immutable();
            //PassByValueAndRef();

            IGradeTracker book = CreateGradeBook();

            try
            {
                using (FileStream stream = File.Open("grades.txt", FileMode.Open))
                    using (StreamReader reader = new StreamReader(stream))
                    {
                        string line = reader.ReadLine();
                        while (line != null)
                        {
                            float grade = float.Parse(line);
                            book.AddGrade(grade);
                            line = reader.ReadLine();
                        }
                    }
            }
            catch (FileNotFoundException ex)
            {
                Console.WriteLine("Could not locate the file grades.txt");
                return;
            }
            catch (UnauthorizedAccessException ex)
            {
                Console.WriteLine("No access");
                return;
            }

            //book.DoSomething();
            //book.WriteGrades(Console.Out);

            foreach (float grade in book)
            {
                Console.WriteLine(grade);
            }

            try
            {
                //Console.WriteLine("Please enter a name for the book");
                //string priv = Console.ReadLine();
                //while (priv=="")
                //{
                //    Console.WriteLine("Please insert correct value");
                //    priv = Console.ReadLine();
                //}
                //book.Name = priv;
            }
            catch (ArgumentException)
            {
                Console.WriteLine("Invalid name");
            }

            GradeStatistics stats = book.ComputeStatistics();

            //book.NameChanged += OnNameChanged;
            //book.NameChanged += OnNameChanged;
            //book.NameChanged += OnNameChanged2;
            //book.NameChanged -= OnNameChanged;

            //book.Name = "Allen's book";

            //WriteNames(book.Name);

            Console.WriteLine(book.Name);

            Console.WriteLine(stats.AverageGrade);
            Console.WriteLine(stats.LowestGrade);
            Console.WriteLine(stats.HighestGrade);
            Console.WriteLine("{0} {1}", stats.LetterGrade, stats.Description);
        }
Ejemplo n.º 29
0
        static void Main(string[] args)
        {
            //GradeBook book = new GradeBook("Aido knygos");

            //GradeBook book = new ThrowAwayGradeBook("Aido knyga"); //cia jau OOP
            IGradeTracker book = CraeteGradeBook();


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


            //FileStream stream = null;
            //StreamReader reader = null;

            try
            {
                using (FileStream stream = File.Open("grades.txt", FileMode.Open)) //sitaip galima panaudoti uzsing kuris turi magic closing ir tada nereikia finally
                    using (StreamReader reader = new StreamReader(stream))         //tokiu atveju net ir pagaunant exceptiona bus uzdaromas filas cia lower level dirbant su filu
                    {
                        string line = reader.ReadLine();

                        //string[] lines = File.ReadAllLines("grades.txt"); //read all line nevisada tinka nes gali but filas per didelis ir poan
                        //foreach (string line in lines)

                        while (line != null)
                        {
                            book.AddGrade(float.Parse(line));
                            line = reader.ReadLine();
                        }
                        //reader.Close();  //butinai reikiauzdaryt bet cia negerai nes jei exceptionas pasitaikys tada numes koda kitur ir neuzdarys
                        //stream.Close();
                    }
            }
            catch (FileNotFoundException ex)
            {
                Console.WriteLine("File not valid grade.txt");
                return;
            }
            catch (UnauthorizedAccessException ex)   //gali gaudyti kiek nori exceptionu
            {
                Console.WriteLine("you dont have access to grade.txt");
                return;
            }
            //finally
            //{
            //    if (reader != null)
            //    {
            //        reader.Close();  //cia vienas is budu kad viska uzdarytufinally kodas visada suveiks nesvarbu ar exceptionas ar kitka
            //    }

            //    if (stream != null)
            //    {
            //        stream.Close();  //bet tada reader ir stream deklaruoti outside try
            //    }
            // }

            //book.DoSomething();
            //book.WriteGrades(Console.Out);

            foreach (float grade in book)
            {
                Console.WriteLine(grade);
            }

            int j;

            do
            {
                try
                {
                    //Console.WriteLine("Please enter the name for the book");
                    //book.Name = Console.ReadLine();
                    j = 1;
                }
                catch (ArgumentException ex)  //ex jei nenaudojamas jo nebutina rasyti
                {
                    Console.WriteLine("Invalid name");
                    j = 2;
                }
            } while (j != 1);

            GradeStatistics stats = book.ComputeStatistics();

            Console.WriteLine(stats.AverageGrade);
            Console.WriteLine(stats.HighestGrade);
            Console.WriteLine(stats.LowestGrade);

            //Console.WriteLine(stats.AvarageLetterGrade);
            //Console.WriteLine(stats.GradeDescription);

            Console.WriteLine("Your grade is {0} {1}", stats.AvarageLetterGrade, stats.GradeDescription);
        }
Ejemplo n.º 30
0
        static void Main(string[] args)
        {
            IGradeTracker book = CreateGradeBook();

            book.AddGrade(95);
            book.AddGrade(93);
            book.AddGrade(99.9f);
            book.AddGrade(76.7f);
            book.AddGrade(76.7f);



            try
            {
                //string[] lines = File.ReadAllLines(@"C:\Users\aidas\OneDrive\Documents\Visual Studio 2015\Projects\C# Fundamentals with C# 5.0 3rd time\Grades\Grades\bin\Debug\grades.txt");
                //foreach (string line in lines)
                //{
                //    book.AddGrade(float.Parse(line));
                //}

                using (FileStream stream = File.Open("grades.txt", FileMode.Open))
                    using (StreamReader reader = new StreamReader(stream))
                    {
                        string line = reader.ReadLine();
                        while (line != null)
                        {
                            book.AddGrade(float.Parse(line));
                            line = reader.ReadLine();
                        }
                    }
            }
            catch (FileNotFoundException ex)
            {
                Console.WriteLine("Tokio failo neradome, todel programa baigiasi" + ex.Message);
                return;
            }
            //finally
            //{
            //    if (reader!=null)
            //    {
            //        reader.Close();
            //    }

            //    if (stream != null)
            //    {
            //        stream.Close();
            //    }
            //}

            book.DoSomething();
            book.WriteGrades(Console.Out);



            GradeStatistics stats = book.ComputeStatistics();

            book.NameChanged += OnNameChanged;
            book.NameChanged += OnNameChanged2;
            book.NameChanged += OnNameChanged;
            book.NameChanged += OnNameChanged;

            book.NameChanged -= OnNameChanged;

            try
            {
                //Console.WriteLine("iveskite varda");
                //book.Name = Console.ReadLine();
            }
            catch (ArgumentException ex)
            {
                Console.WriteLine($"pagavaom exceptiona {ex.Message}");
            }


            WriteNames(book.Name);

            Console.WriteLine($"Vidurkis {stats.average}");
            Console.WriteLine($"Zemiausias {stats.LowestGrade}");
            Console.WriteLine($"Didziausias {stats.BiggestGrade}");
            Console.WriteLine($"Letter grades is {Char.ToUpper(stats.LetterGrade)} whick is {stats.Description.First().ToString().ToUpper() + stats.Description.Substring(1)}");

            book.Name = "Vanagas";

            //book.Name = Console.ReadLine();
        }
Ejemplo n.º 31
0
        //Can I set this main to public?
        public static void Main(string[] args)
        {
            SpeechSpeaker.Speaker();

            IGradeTracker book = CreateGradeBook();

            try
            {
                using (FileStream stream = File.Open("grades.txt", FileMode.Open))
                    using (StreamReader reader = new StreamReader(stream))
                    {
                        string line = reader.ReadLine();
                        while (line != null)
                        {
                            float grade = float.Parse(line);
                            book.AddGrade(grade);
                            line = reader.ReadLine();
                        }
                    }

                //book.AddGrade(91f);
                //book.AddGrade(89.1f);
                //book.AddGrade(75f);
            }
            catch (FileNotFoundException ex)
            {
                Console.WriteLine("Could not locate the file grades.txt");
                return;
            }
            catch (UnauthorizedAccessException ex)
            {
                Console.WriteLine("No access");
                return;
            }

            foreach (float grade in book)
            {
                Console.WriteLine(grade);
            }

            try
            {
                Console.WriteLine("Please enter a name for the book");
                book.Name = Console.ReadLine();
                //Delegate playground.
                //Book call deledgate Namgechanged. If namechanged is not null, then
                book.NameChanged += OnNameChanged;
                book.NameChanged += OnNameChanged;
                book.NameChanged += OnNameChanged2;
                book.NameChanged -= OnNameChanged;
            }
            catch (ArgumentException)
            {
                Console.WriteLine("Invalid name");
            }


            book.Name = "Allen's Book";
            WriteNames(book.Name);
            GradeStatistics stats = book.ComputeStatistics();

            Console.WriteLine(stats.AverageGrade);
            Console.WriteLine(stats.LowestGrade);
            Console.WriteLine(stats.HighestGrade);
            Console.WriteLine("{0} {1}", stats.LetterGrade, stats.Description);

            Console.WriteLine("Press any key to exist");
            Console.ReadLine();
        }
Ejemplo n.º 32
0
        static void Main(string[] args)
        {
            // SpeechSynthesizer synth = new SpeechSynthesizer();
            //synth.Speak("Hello, World");


            //Arrays();
            //Immutable();
            //PassByValueAndRef();

            IGradeTracker book = CreateGradebook();

            try
            {
                using (FileStream fs = File.Open("grades.txt", FileMode.Open))
                    using (StreamReader sr = new StreamReader(fs))
                    {
                        string line = sr.ReadLine();

                        while (line != null)
                        {
                            float grade = float.Parse(line);
                            book.AddGrade(grade);
                            line = sr.ReadLine();
                        }
                    }
                //string[] lines = File.ReadAllLines("grades.txt");

                //foreach (string line in lines)
                //{
                //    float grade = float.Parse(line);
                //    book.AddGrade(grade);
                //}
            }
            catch (FileNotFoundException ex)
            {
                Console.WriteLine("File not found");
                return;
            }
            catch (UnauthorizedAccessException ex)
            {
                Console.WriteLine("No access");
                return;
            }
            //finally
            //{
            //    if (sr != null)
            //    {
            //        sr.Close();
            //    }

            //    if (fs != null)
            //    {
            //        fs.Close();
            //    }

            //}


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


            foreach (float grade in book)
            {
                Console.WriteLine(grade);
            }



            book.DoSomething();


            book.WriteGrades(Console.Out);

            //Console.WriteLine(book.Name);

            // Method 1 for delegate
            //book.NameChanged = new NamedChangeDelegate(OnNameChanged);

            // Method 2 for delegate
            //book.NameChanged += OnNameChanged;

            //book.NameChanged += OnNameChanged;
            //book.NameChanged += OnNameChanged2;
            //book.Name = "Dick";

            //Console.WriteLine(book.Name);

            //WriteNames("hello", "Jack", "bob", "Dick");

            GradeStatistics stats = book.ComputeStatistics();


            Console.WriteLine(stats.LetterGrade);

            Console.WriteLine(stats.Description);

            //int number = 20;

            //WriteBytes(number);
            //WriteBytes(stats.AverageGrade);


            Console.WriteLine(stats.AverageGrade);
            Console.WriteLine(stats.LowestGrade);
            Console.WriteLine(stats.HighestGrade);

            Console.ReadKey();
        }