Esempio n. 1
0
        public static void CreateCoursesList(int count)
        {
            Console.WriteLine($"\nPlease, add {count} courses. Format: <name>//<capacity>");
            Regex pattern = new Regex(@"^[\w\-\#]+\/\/\d{1,5}$");

            for (int i = 0; i < count; i++)
            {
                Console.Write("\nCourse " + (i + 1) + "\n");
                var input = Console.ReadLine();

                if (pattern.IsMatch(input))
                {
                    string[] courseInfos = input.Split(new string[] { "//" }, StringSplitOptions.None);
                    string   cName       = courseInfos[0];
                    int      cCapacity   = int.TryParse(courseInfos[1], out cCapacity) ? cCapacity : 0;

                    Academy.AddCourse(cName, cCapacity);
                }
                else
                {
                    Console.WriteLine("Wrong format! Please, try again.");
                    i--;
                }
            }
        }
Esempio n. 2
0
        public static void CreateCoursesList(int count)
        {
            Console.WriteLine($"\nPlease, add {count} courses. Format: <name>//<duration>//<capacity>");
            for (int i = 0; i < count; i++)
            {
                Console.Write("\nCourse " + (i + 1) + "\n");
                string[] courseInfos = Console.ReadLine().Split(new string[] { "//" }, StringSplitOptions.None);
                string   cName       = courseInfos[0];
                int      cDuration   = int.TryParse(courseInfos[1], out cDuration) ? cDuration : 0;
                int      cCapacity   = int.TryParse(courseInfos[2], out cCapacity) ? cCapacity : 0;

                Academy.AddCourse(cName, cDuration, cCapacity);
            }
        }