예제 #1
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();
        }
예제 #2
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();
        }