Ejemplo n.º 1
0
        private static void Main()
        {
            var substr = Exceptions.Subsequence("Hello!".ToCharArray(), 2, 3);
            Console.WriteLine(substr);

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

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

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

            Console.WriteLine(Exceptions.ExtractEnding("I love C#", 2));
            Console.WriteLine(Exceptions.ExtractEnding("Nakov", 4));
            Console.WriteLine(Exceptions.ExtractEnding("beer", 4));
            //// Console.WriteLine(ExtractEnding("Hi", 100));

            Console.WriteLine("23 is {0}.", Exceptions.CheckPrime(23) ? "prime" : "not prime");
            Console.WriteLine("33 is {0}.", Exceptions.CheckPrime(23) ? "prime" : "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);
        }
        public static void Main()
        {
            var substr = Subsequence.GetSubsequence("Hello!".ToCharArray(), 2, 3);
            Console.WriteLine(substr);

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

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

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

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

            try
            {
                PrimeChecker.CheckPrime(23);
                Console.WriteLine("23 is prime.");
            }
            catch (Exception ex)
            {
                Console.WriteLine("23 is not prime", ex);
            }

            try
            {
                PrimeChecker.CheckPrime(33);
                Console.WriteLine("33 is prime.");
            }
            catch (Exception ex)
            {
                Console.WriteLine("33 is not prime", ex);
            }

            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.CalculateAverageExamResultInPercents();
            Console.WriteLine("Average results of Peter Petrov= {0:p0}", peterAverageResult);

            List<Exam> ivanExams = new List<Exam>() { }; // test with empty list
            Student ivan = new Student("Ivan", "Ivanov", ivanExams);
            double ivanAverageResult = ivan.CalculateAverageExamResultInPercents(); // logs "The student has no exams!" - this the right behavior
            Console.WriteLine("Average results of Ivan Ivanov = {0:p0}", ivanAverageResult); // logs "Average results of Ivan Ivanov = 0%" - this the right behavior
        }
        public static void Main()
        {
            var substr = Helpers.Subsequence("Hello!".ToCharArray(), 2, 3);
            Console.WriteLine(substr);

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

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

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

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

            try
            {
                Console.WriteLine(Helpers.ExtractEnding("Hi", 100));
            }
            catch (ArgumentOutOfRangeException exception)
            {
                Console.Error.WriteLine(exception.Message);
            }

            var primeNumber = 23;

            Console.WriteLine(primeNumber + " is prime." + Helpers.CheckPrime(primeNumber));

            var notPrimeNumber = 23;

            Console.WriteLine(notPrimeNumber + " is prime." + Helpers.CheckPrime(notPrimeNumber));

            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);
        }
        public static void Main()
        {
            var substr = SubArrayMethods.Subsequence("Hello!".ToCharArray(), 2, 3);
            Console.WriteLine(substr);

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

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

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

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

            try
            {
                Console.WriteLine(SubArrayMethods.ExtractEnding("Hi", 100));
            }
            catch (ArgumentNullException ex)
            {
                Console.WriteLine(ex.Message);
            }
            catch (ArgumentOutOfRangeException ex)
            {
                Console.WriteLine(ex.Message);
            }

            Console.WriteLine(string.Format("{0} is prime: {1}", 23, PrimeNumbers.Check(23)));
            Console.WriteLine(string.Format("{0} is prime: {1}", 33, PrimeNumbers.Check(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.º 5
0
        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));

            var validPrime = 23;
            var isPrime = Utils.CheckPrime(validPrime);
            Console.WriteLine(validPrime + " is prime: " + isPrime);

            var invalidNumber = -23;
            try
            {
                Utils.CheckPrime(invalidNumber);
                Console.WriteLine(invalidNumber + " is prime.");
            }
            catch (Exception ex)
            {
                Console.WriteLine(invalidNumber + " is not prime. ");
            }

            var peterExams = new List<Exam.Exam>()
            {
                new SimpleMathExam(2),
                new CSharpExam(55),
                new CSharpExam(100),
                new SimpleMathExam(1),
                new CSharpExam(0),
            };
            Student peter = new Student("Peter", "Petrov", peterExams);
            var peterAverageResult = peter.CalculateAverageExamResultInPercents();
            Console.WriteLine("Average results = {0:p0}", peterAverageResult);
        }
        static void Main()
        {
            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));

            Console.WriteLine(StringUtils.ExtractEnding("I love C#", 2));
            Console.WriteLine(StringUtils.ExtractEnding("Nakov", 4));
            Console.WriteLine(StringUtils.ExtractEnding("beer", 4));
            try
            {
                Console.WriteLine(StringUtils.ExtractEnding("Hi", 100));
            }
            catch (ArgumentException ex)
            {
                Console.WriteLine("Count is more than the length of the string");
            }

            Console.WriteLine("23 is prime ? -> {0}", MathUtils.IsPrime(23));

            Console.WriteLine("33 is prime? -> {0}", MathUtils.IsPrime(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);
        }
        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));

            try
            {
                Console.WriteLine(Utils.ExtractEnding("I love C#", 2));
            }
            catch (ArgumentException ex)
            {
                Console.WriteLine(ex.ParamName);
            }

            try
            {
                Console.WriteLine(Utils.ExtractEnding("Nakov", 4));
            }
            catch (ArgumentException ex)
            {
                Console.WriteLine(ex.ParamName);
            }

            try
            {
                Console.WriteLine(Utils.ExtractEnding("beer", 4));
            }
            catch (ArgumentException ex)
            {
                Console.WriteLine(ex.ParamName);
            }

            try
            {
                Console.WriteLine(Utils.ExtractEnding("Hi", 100));
            }
            catch (ArgumentException ex)
            {
                Console.WriteLine(ex.ParamName);
            }

            Utils.CheckPrime(23);
            Utils.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);
        }
        static void Main()
        {
            var substr = MathUtils.Subsequence("Hello!".ToCharArray(), 2, 3);
            Console.WriteLine(substr);

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

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

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

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

            if (MathUtils.CheckPrime(23))
            {
                Console.WriteLine("23 is prime.");
            }
            else
            {
                Console.WriteLine("23 is not prime");
            }

            if (MathUtils.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);
        }