Ejemplo n.º 1
0
        public static void Main()
        {
            try
            {
                var text = Utils.Subsequence("Hello!".ToCharArray(), 2, 3);
                Console.WriteLine(text);

                var halfOfArrayContent = Utils.Subsequence(new[] { -1, 3, 2, 1 }, 0, 2);
                Console.WriteLine(string.Join(" ", halfOfArrayContent));

                var fullArrayContent = Utils.Subsequence(new[] { -1, 3, 2, 1 }, 0, 4);
                Console.WriteLine(string.Join(" ", fullArrayContent));

                var emptyarr = Utils.Subsequence(new[] { -1, 3, 2, 1 }, 0, 0);
                Console.WriteLine(string.Join(" ", emptyarr));

                Console.WriteLine(Utils.ExtractEnding("I love C#", 2));
                Console.WriteLine(Utils.ExtractEnding("Nakov", 4));

                // uncomment below two lines to enable exception throw

                // Console.WriteLine(Utils.ExtractEnding("beer", 4));
                // Console.WriteLine(Utils.ExtractEnding("Hi", 100));

                int primeNumber = 23;
                bool isPrimeNumber = Utils.CheckPrime(primeNumber);
                Console.WriteLine("{0} is" + (isPrimeNumber ? " " : " not ") + "prime.", primeNumber);

                primeNumber = 33;
                isPrimeNumber = Utils.CheckPrime(primeNumber);
                Console.WriteLine("{0} is" + (isPrimeNumber ? " " : " not ") + "prime.", primeNumber);

                primeNumber = -1;
                isPrimeNumber = Utils.CheckPrime(primeNumber);
                Console.WriteLine("{0} is" + (isPrimeNumber ? " " : " not ") + "prime.", primeNumber);

                var peterExams = new List<Exam>()
                {
                    new SimpleMathExam(2), 
                    new CSharpExam(55), 
                    new CSharpExam(100), 
                    new SimpleMathExam(1), 
                    new CSharpExam(0)
                };

                var peter = new Student("Peter", "Petrov", peterExams);
                double peterAverageResult = peter.CalcAverageExamResultInPercents();
                Console.WriteLine("Average results = {0:p0}", peterAverageResult);
            }
            catch (ArgumentNullException ex)
            {
                Console.WriteLine(ex.Message);
            }
            catch (ArgumentOutOfRangeException ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
        public static void Main()
        {
            var substr = Utils.Subsequence("Hello!".ToCharArray(), 2, 3);
            Console.WriteLine(substr);

            var subarr = Utils.Subsequence(new int[] { -1, 3, 2, 1 }, 0, 2);
            Console.WriteLine(string.Join(" ", subarr));

            var allarr = Utils.Subsequence(new int[] { -1, 3, 2, 1 }, 0, 4);
            Console.WriteLine(string.Join(" ", allarr));

            var emptyarr = Utils.Subsequence(new int[] { -1, 3, 2, 1 }, 0, 0);
            Console.WriteLine(string.Join(" ", emptyarr));

            Console.WriteLine(Utils.ExtractEnding("I love C#", 2));
            Console.WriteLine(Utils.ExtractEnding("Nakov", 4));
            Console.WriteLine(Utils.ExtractEnding("beer", 4));

            //Console.WriteLine(Utils.ExtractEnding("Hi", 100));
            if (Utils.CheckPrime(23))
            {
                Console.WriteLine("23 is prime.");
            }
            else
            {
                Console.WriteLine("23 is not prime");
            }

            if (Utils.CheckPrime(33))
            {
                Console.WriteLine("33 is prime.");
            }
            else
            {
                Console.WriteLine("33 is not prime");
            }

            List<Exam> peterExams = new List<Exam>()
            {
                new SimpleMathExam(2),
                new CSharpExam(55),
                new CSharpExam(100),
                new SimpleMathExam(1),
                new CSharpExam(0),
            };
            Student peter = new Student("Peter", "Petrov", peterExams);
            double peterAverageResult = peter.CalcAverageExamResultInPercents();
            Console.WriteLine("Average results = {0:p0}", peterAverageResult);
        }
Ejemplo n.º 3
0
        public static void Main()
        {
            var substr = ExtensionMethods.Subsequence("Hello!".ToCharArray(), 2, 3);
            Console.WriteLine(substr);

            var subarr = ExtensionMethods.Subsequence(new int[] { -1, 3, 2, 1 }, 0, 2);
            Console.WriteLine(string.Join(" ", subarr));

            var allarr = ExtensionMethods.Subsequence(new int[] { -1, 3, 2, 1 }, 0, 4);
            Console.WriteLine(string.Join(" ", allarr));

            var emptyarr = ExtensionMethods.Subsequence(new int[] { -1, 3, 2, 1 }, 0, 0);
            Console.WriteLine(string.Join(" ", emptyarr));

            Console.WriteLine(ExtensionMethods.ExtractEnding("I love C#", 2));
            Console.WriteLine(ExtensionMethods.ExtractEnding("Nakov", 4));
            Console.WriteLine(ExtensionMethods.ExtractEnding("beer", 4));

            // Console.WriteLine(ExtensionMethods.ExtractEnding("Hi", 100));
            try
            {
                Console.WriteLine(ExtensionMethods.ExtractEnding("Hi", 100));
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error message:");
                Console.WriteLine(ex.GetType().Name);
                Console.WriteLine(ex.Message);
            }

            Console.WriteLine("23 is prime? --> {0}", ExtensionMethods.CheckPrime(23));
            Console.WriteLine("33 is prime? --> {0}", ExtensionMethods.CheckPrime(33));

            List<Exam> peterExams = new List<Exam>()
            {
            new SimpleMathExam(2),
            new CSharpExam(55),
            new CSharpExam(100),
            new SimpleMathExam(1),
            new CSharpExam(0),
            };
            Student peter = new Student("Peter", "Petrov", peterExams);
            double peterAverageResult = peter.CalcAverageExamResultInPercents();
            Console.WriteLine("Average results = {0:p0}", peterAverageResult);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Mains this instance.
        /// </summary>
        public static void Main()
        {
            try
            {
                var substr = StringUtils.Subsequence("Hello!".ToCharArray(), 2, 3);
                Console.WriteLine(substr);

                var subarr = StringUtils.Subsequence(new int[] { -1, 3, 2, 1 }, 0, 2);
                Console.WriteLine(string.Join(" ", subarr));

                var allarr = StringUtils.Subsequence(new int[] { -1, 3, 2, 1 }, 0, 4);
                Console.WriteLine(string.Join(" ", allarr));

                var emptyarr = StringUtils.Subsequence(new int[] { -1, 3, 2, 1 }, 0, 0);
                Console.WriteLine(string.Join(" ", emptyarr));
            }
            catch (ArgumentNullException ane)
            {
                Console.WriteLine(ane.Message);
            }
            catch (ArgumentOutOfRangeException aore)
            {
                Console.WriteLine(aore.Message);
            }

            try
            {
                Console.WriteLine(StringUtils.ExtractEnding("I love C#", 2));
                Console.WriteLine(StringUtils.ExtractEnding("Nakov", 4));
                Console.WriteLine(StringUtils.ExtractEnding("beer", 4));
                Console.WriteLine(StringUtils.ExtractEnding("Hi", 100));
            }
            catch (ArgumentNullException ane)
            {
                Console.WriteLine(ane.Message);
            }
            catch (ArgumentOutOfRangeException aore)
            {
                Console.WriteLine(aore.Message);
            }

            try
            {
                int[] numbersToCheck = new int[] { 23, 33, 1, 0 };

                for (int i = 0; i < numbersToCheck.Length; i++)
                {
                    bool isPrime = MathUtils.CheckIfPrime(numbersToCheck[i]);
                    Console.WriteLine("{0} {1} prime.", numbersToCheck[i], isPrime ? "is" : "is NOT");
                }
            }
            catch (ArgumentOutOfRangeException aore)
            {
                Console.WriteLine(aore.Message);
            }

            try
            {
                List<Exam> peterExams = new List<Exam>()
                {
                    new SimpleMathExam(2),
                    new CSharpExam(55, 0, 100),
                    new CSharpExam(100, 0, 100),
                    new SimpleMathExam(1),
                    new CSharpExam(0, 0, 100),
                };
                Student peter = new Student("Peter", "Petrov", peterExams);
                double peterAverageResult = peter.CalcAverageResultInPercent();
                Console.WriteLine("Average results = {0:p0}", peterAverageResult);

                peterExams.Add(new CSharpExam(550, 0, 100));
            }
            catch (ArgumentOutOfRangeException aore)
            {
                Console.WriteLine(aore.Message);
            }
        }