예제 #1
0
        public GradeBookTests()
        {
            var book = new GradeBook();

            book.AddGrade(90f);
            book.AddGrade(100f);
            book.AddGrade(50f);

            _stats = book.ComputeStatistics();
        }
예제 #2
0
        public GradeStatistics ComputeStatistics()
        {
            GradeStatistics stats = new GradeStatistics();

            float sum = 0;

            foreach (float 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);
        }
예제 #3
0
        public void TestComputeStatistics()
        {
            GradeBook book = new GradeBook();

            book.AddGrade(77);
            book.AddGrade(88);
            book.AddGrade(99);

            GradeStatistics stats = new GradeStatistics();

            stats = book.ComputeStatistics();

            Assert.AreEqual(88, stats.AverageGrade);
            Assert.AreEqual(99, stats.HighestGrade);
            Assert.AreEqual(77, stats.LowestGrade);
        }
예제 #4
0
        public void ComputesAverageGrade()
        {
            GradeBook book = new GradeBook();

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


            GradeStatistics result = book.ComputeStatistics();

            Assert.AreEqual(85.166, result.AverageGrade, 0.001);

            //p.s: No need to store the whole digit in gradebook
            //comparing double precision floaitng point
            //double delta can be 85.16 and double delta will be 0.01
        }
예제 #5
0
        public override GradeStatistics ComputeStatistics()
        {
            Console.WriteLine("GradeBook::ComputeStatistics");
            GradeStatistics stats = new GradeStatistics();

            float sum = 0;

            foreach (float 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);
        }
예제 #6
0
        public GradeStatistics Statistics()
        {
            var stats = GradeStatistics.Create();

            stats.High = double.MinValue;
            stats.Low  = double.MaxValue;

            foreach (double grade in grades)
            {
                stats.High   = Math.Max(grade, stats.High);
                stats.Low    = Math.Min(grade, stats.Low);
                stats.Total += grade;
            }

            stats.Average = grades.Count == 0 ? 0 : stats.Total / grades.Count;

            return(stats);
        }
예제 #7
0
        static void Main(string[] args)
        {
            SpeechSynthesizer synth = new SpeechSynthesizer();

            synth.Speak("Hello! This is the grade book program");

            GradeBook book = new GradeBook();

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

            GradeStatistics stats = book.ComputeStatistics();

            Console.WriteLine(stats.AverageGrade);
            Console.WriteLine(stats.HighestGrade);
            Console.WriteLine(stats.LowestGrade);
        }
예제 #8
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);
        }
        public GradeStatistics ComputeStatistics()
        {
            GradeStatistics stats = new GradeStatistics();


            float sum = 0f;

            foreach (float grade in grades)
            {
                /**
                if (grade > stats.HighestGrade)
                {
                    stats.HighestGrade = grade;
                }
                 * */
                stats.HighestGrade = Math.Max(grade, stats.HighestGrade);
                stats.LowestGrade = Math.Min(grade, stats.LowestGrade);
                sum = sum + grade;
            }

            stats.AverageGrade = sum / grades.Count;
            return stats;
        }
예제 #10
0
        public void ComputeAverageGradeGrade_WithValidData_ReturnGradesAdded()
        {
            GradeStatistics statistics = BuildGradeStatistics();

            Assert.Equal(statistics.AverageGrade, 62.5f);
        }
예제 #11
0
        public void ComputeHighestGrade_WithValidData_ReturnGradesAdded()
        {
            GradeStatistics statistics = BuildGradeStatistics();

            Assert.Equal(statistics.HighestGrade, 100f);
        }
예제 #12
0
        public void LowerstGrade()
        {
            GradeStatistics states = Statistics(book1);

            Assert.AreEqual(80, states.LowerstGrade);
        }
예제 #13
0
 public void CreateTest()
 {
     Assert.IsType <GradeStatistics>(GradeStatistics.Create());
 }
예제 #14
0
        static void Main(string[] args)
        {
            // Cultures
            CultureInfo enUS = new CultureInfo("en-US");
            CultureInfo enGB = new CultureInfo("en-GB");
            CultureInfo frFR = new CultureInfo("fr-FR");
            CultureInfo deDE = new CultureInfo("de-DE");

            // Change in current thread's culture
            // Now floating point numbers will be written with dot separators
            Thread.CurrentThread.CurrentCulture = enUS;

            using (SpeechSynthesizer synthesizer = new SpeechSynthesizer())
            {
                synthesizer.Rate = -2;

                // Changing current voice by getting different cultures
                // Get installed voices
                var voices = synthesizer.GetInstalledVoices(enUS);

                if (voices.Count > 0)
                {
                    // Speak!
                    synthesizer.SelectVoice(voices[0].VoiceInfo.Name);
                    synthesizer.Speak(@"Three Rings for the Elven-kings under the sky,
                                        Seven for the Dwarf-lords in their halls of stone,
                                        Nine for Mortal Men doomed to die,
                                        One for the Dark Lord on his dark throne
                                        In the Land of Mordor where the Shadows lie.
                                        One Ring to rule them all, One Ring to find them,
                                        One Ring to bring them all, and in the darkness bind them,
                                        In the Land of Mordor where the Shadows lie.
                                        ");
                }

                // Show installed voices
                Console.WriteLine("Installed Voices");
                foreach (var v in synthesizer.GetInstalledVoices().Select(v => v.VoiceInfo))
                {
                    Console.WriteLine("Name:{0}, Gender:{1}, Age:{2}", v.Description, v.Gender, v.Age);
                }
            }

            Console.Write("How many hours of sleep did you have? > ");

            try
            {
                int hours = Int32.Parse(Console.ReadLine());

                if (hours >= 12)
                {
                    Console.WriteLine("You slept for too much time!");
                }
                else if (hours >= 8)
                {
                    Console.WriteLine("Good. You had enough time to sleep!");
                }
                else
                {
                    Console.WriteLine("You need more time to sleep");
                }
            }
            catch (FormatException e)
            {
                Console.WriteLine("You didn't type a number...");
            }

            GradeBook grades = new GradeBook();

            grades.NameChanged += new NameChangedDelegate(OnNameChange);
            grades.NameChanged += new NameChangedDelegate(OnNameChangeConcat);

            grades.Name = "California";
            grades.Name = "New York";

            grades.NameChanged -= OnNameChangeConcat;

            grades.NameChanged += OnNameChange;
            grades.NameChanged += OnNameChangeConcat;

            grades.Name = "North Carolina";

            grades.AddGrade(new Grade(9.2, 8.6, 7.1, 7.3, 6.2));
            grades.AddGrade(new Grade(10.0, 9.3, 5.4, 5.1, 4.5));
            grades.AddGrade(new Grade(7.8, 7.5, 6.9, 6.3, 10.0));

            Console.WriteLine(grades);

            var GS = new GradeStatistics(grades);

            GS.Compute();

            Console.WriteLine($"Maximum Grade: {GS.Maximum}\nMinimum Grade: {GS.Minimum}\nAverage: {GS.Average}");

            WriteAsBytes(365);

            Console.WriteLine();

            Console.ReadKey();
        }
예제 #15
0
        public void HighestGrade()
        {
            GradeStatistics states = Statistics(book1);

            Assert.AreEqual(100, states.HighestGrade);
        }
예제 #16
0
        public void AverageGradeGradeBook()
        {
            GradeStatistics states = Statistics(book1);

            Assert.AreEqual(90, states.AverageGrade);
        }
예제 #17
0
        public void AverageGradeThrowAwayGB()
        {
            GradeStatistics states = Statistics(book2);

            Assert.AreEqual(95, states.AverageGrade);
        }