Exemple #1
0
 private static void AddGrades(IGradeTracker book)
 {
     book.AddGrade(91);
     book.AddGrade(89.5f);
     book.AddGrade(75);
     book.AddGrade(20);
 }
Exemple #2
0
 private static void AddGrades(IGradeTracker book)
 {
     book.AddGrade(111);
     book.AddGrade(55.5f);
     book.AddGrade(0);
     book.AddGrade(100);
     book.AddGrade(200);
 }
 private static void AddGrades(IGradeTracker book)
 {
     book.AddGrade(91);
     book.AddGrade(89.9f);
     //GradeBook book1 = book;//to pointer poining to the same address or two references variable pointing to the same address in the memory
     //it means runtime will copy the address of the book to book1,now we can use the book1 and book variable to access the same obejct memory location
     book.AddGrade(75);
 }
 private static void AddNameAndGrades(IGradeTracker book)
 {
     book.NameChanged += new NameChangedDelegate(OnNameChanged);
     book.Name         = "Fernando's Grades";
     book.Name         = "My Grades";
     book.AddGrade(91);
     book.AddGrade(85.5f);
     book.AddGrade(75);
 }
Exemple #5
0
        private static void AddGrades(IGradeTracker book)
        {
            Console.WriteLine("\nHow many grades do you want to add?:");
            string input = Console.ReadLine();

            if (Int32.TryParse(input, out int num))
            {
                /* Yes input could be parsed and we can now use number in this code block
                 * scope */
                for (int i = 0; i < Convert.ToInt32(input); i++)
                {
Add:
                    Console.Write("Enter grade " + (i + 1) + ": ");
                    string gradeInput = Console.ReadLine();

                    if (float.TryParse(gradeInput, out float gradeAddition))
                    {
                        book.AddGrade(gradeAddition);
                    }
                    else
                    {
                        Console.WriteLine("Not a valid number, please try again.");
                        goto Add;
                    }
                }
            }
            else
            {
                /* No, input could not be parsed to an integer */
                AddGrades(book);
            }
        }
Exemple #6
0
 private static void AddGrades(IGradeTracker book1)
 {
     try
     {
         Console.WriteLine("Please enter first grade point: ");
         book1.AddGrade(float.Parse(Console.ReadLine()));
         Console.WriteLine("Please enter second grade point");
         book1.AddGrade(float.Parse(Console.ReadLine()));
         Console.WriteLine("Please enter third grade point");
         book1.AddGrade(float.Parse(Console.ReadLine()));
         Console.WriteLine("------------------");
     }
     catch (ArgumentException ex)
     {
         Console.WriteLine(ex.Message);
     }
 }
Exemple #7
0
        static void Main(string[] args)
        {
            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)
            {
                Console.WriteLine("Could not locate file");
                Console.ReadLine();
                return;
            }
            catch (UnauthorizedAccessException)
            {
                Console.WriteLine("You dont have access to the file");
                Console.ReadLine();
                return;
            }

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

            try
            {
                //Console.WriteLine("Please enter a name");
                //book.Name = Console.ReadLine();
            }
            catch (ArgumentException)
            {
                Console.WriteLine("Invalid 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.ReadLine();
        }
Exemple #8
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();
        }
        // //Save grades in a txt file
        // private static void SaveGrades(IGradeTracker book)
        // {
        //     using (StreamWriter outputFile = File.CreateText("grades.txt"))
        //     {
        //         book.WriteGrades(outputFile);
        //     }
        // }

        private static void AddGrades(IGradeTracker book)
        {
            //Adding grades to the grades list.
            Console.WriteLine("Please enter four grades:");
            for (int i = 0; i < 4; i++)
            {
                float input = float.Parse(Console.ReadLine());
                book.AddGrade(input);
            }
        }
        static void Main(string[] args)
        {
            IGradeTracker book = CreateGradeBook();

            book.Name         = "Bethany's Grade Book.";
            book.NameChanged += OnNameChanged;
            book.Name         = "Joakim's Grade Book.";
            book.AddGrade(91);
            book.AddGrade(89.5f);
            book.AddGrade(75);

            IGradeTracker book2 = CreateGradeBook();

            book2.AddGrade(54);
            book2.AddGrade(32.5f);

            WriteResults(book);
            Console.WriteLine("\n--BREAK--\n");
            WriteResults(book2);
        }
Exemple #11
0
 private static void AddGrades(IGradeTracker book)
 {
     book.AddGrade(91);
     book.AddGrade(89.5f);
     book.AddGrade(75);
     book.AddGrade(60);
     book.AddGrade(59);
     book.AddGrade(82);
     book.AddGrade(95);
 }
Exemple #12
0
        static void Main(string[] args)
        {
            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)
            {
                Console.WriteLine("Could not locate the file");
                return;
            }
            catch (UnauthorizedAccessException ex)
            {
                Console.WriteLine("You donn't have acces to this file");
                return;
            }

            book.WriteGrades(Console.Out);

            try
            {
                Console.WriteLine("Please enter your name");
                book.Name = Console.ReadLine();
            }
            catch (ArgumentException ex)
            {
                Console.WriteLine("Invalide name");
            }



            GradeStatistics stats = book.ComputeStatistics();

            Console.WriteLine("This is your average grade: " + stats.AverageGrade);
            Console.WriteLine("This is your lowest grade : " + stats.LowestGrade);
            Console.WriteLine("This is your highest grade: " + stats.HighestGrade + "\n");
            Console.WriteLine("Your result is a: " + "{0} {1}", stats.LetterGrade, "\nThat is " + stats.Description);
        }
Exemple #13
0
        static void Main(string[] args)
        {
            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)
            {
                //                Console.WriteLine("File not found din hound");
                return;
            }
            catch (UnauthorizedAccessException)
            {
                Console.WriteLine("none vaild access");
                return;
            }
            foreach (float grade in book)
            {
                Console.WriteLine();
            }

            try
            {
                //Console.WriteLine("PLease skriv nogt do ");
                //book.Name = Console.ReadLine();
            }
            catch (ArgumentException)
            {
                Console.WriteLine("felaktigt namn");
            }


            GradeStatistics stats = book.ComputeStatistics();

            Console.WriteLine(stats.AvergeGrade);
            Console.WriteLine(stats.HighGrade);
            Console.WriteLine(stats.LowestGrade);
            Console.WriteLine("{0} {1}", stats.LetterGrade, stats.Descprition);
        }
Exemple #14
0
        private static void WriteResults(IGradeTracker book)
        {
            GradeStatistics stats = book.ComputeStatistic();

            book.AddGrade(6.5f);

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

            WriteResult("Highest grade", (int)stats.MaxGrade);
            WriteResult("Average grade", stats.AvgGrade);
            WriteResult("Lowest grade", stats.MinGrade);
            WriteResult("Your letter Grade is ", stats.LetterGrade);
            WriteResult("And it is ", stats.LetterGradeDescription);
        }
        private static IGradeTracker CreateGradeBookAndAddGrades(IGradeTracker gradebookobj)
        {
            Console.WriteLine("\nEnter grades in the gradebook.Press END key to stop entering grades:");
            while (true)

            {
                double f1;
                var    result = Console.ReadLine();
                if (!String.IsNullOrWhiteSpace(result))
                {
                    var conversionresult = double.TryParse(result, out f1);
                    gradebookobj.AddGrade(f1);
                }
                else
                {
                    break;
                }
            }

            return(gradebookobj);
        }
Exemple #16
0
 private static void AddGrades(IGradeTracker book)
 {
     book.AddGrade(90);
     book.AddGrade(85);
     book.AddGrade(70);
 }
Exemple #17
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();
        }
Exemple #18
0
 private static void AddGrades(IGradeTracker book)
 {
     book.AddGrade(92);
     book.AddGrade(67.3f);
     book.AddGrade(58);
 }
Exemple #19
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();
        }
Exemple #20
0
 private static void AddGrades(IGradeTracker book) // Changed from GradeBook to GradeTracker to explain abstracts
 {
     book.AddGrade(91);
     book.AddGrade(89.5f);
     book.AddGrade(75);
 }
 private static void AddGrades(IGradeTracker book)
 {
     book.AddGrade(91);
     book.AddGrade(89.5f); //Since we declared it as a float, we need to append it with an f
     book.AddGrade(75);
 }
Exemple #22
0
 private static void AddGrades(IGradeTracker book)
 {
     book.AddGrade(91);
     book.AddGrade(45.5f);
     book.WriteGrade(Console.Out);
 }
Exemple #23
0
 private static void AddGrades(IGradeTracker book)
 {
     book.AddGrade(8);
     book.AddGrade(9.1f);
     book.AddGrade(75);
 }
Exemple #24
0
 private static void AddGrades(IGradeTracker book)
 {
     book.AddGrade(85);
     book.AddGrade(76.4f);
     book.AddGrade(59);
 }
Exemple #25
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);
        }
Exemple #26
0
 private static void AddGrades(IGradeTracker book)
 {
     book.AddGrade(95);
     book.AddGrade(71);
     book.AddGrade(83.3f);
 }
Exemple #27
0
 private static void AddGrades(IGradeTracker book)
 {
     book.AddGrade(91);
     book.AddGrade(85.5f);
     book.AddGrade(71);
 }
Exemple #28
0
 private static void AddingGrades(IGradeTracker book)
 {
     book.AddGrade(91);
     book.AddGrade(89.5f);
     book.AddGrade(75);
 }
Exemple #29
0
 private static void AddGrades(IGradeTracker book)
 {
     book.AddGrade(88);
     book.AddGrade(99);
     book.AddGrade(93);
 }
Exemple #30
0
 private static void AddGrades(IGradeTracker gradeBook)
 {
     gradeBook.AddGrade(90.25f);
     gradeBook.AddGrade(56.2F);
     gradeBook.AddGrade(89.50f);
 }
Exemple #31
0
 private static void AddGrades(IGradeTracker gb1)
 {
     gb1.AddGrade(91);
     gb1.AddGrade(85.2f);
     gb1.AddGrade(75);
 }
Exemple #32
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();
        }
Exemple #33
0
 static void AddGradesToGradebook(IGradeTracker book)
 {
     book.AddGrade(91);
     book.AddGrade(89.5f);
     book.AddGrade(75);
 }