/// <summary> /// Set the method depends on identifier /// </summary> /// <param name="moscow">Moscow method</param> /// <param name="piter">Peter method</param> /// <param name="luckyCount">quantity of lucky tickets</param> /// <param name="method">the identifier</param> /// <param name="tickets">tickets array</param> /// <returns>count of lucky tickets</returns> internal int MethodInitialize(Moscow moscow, Piter piter, int luckyCount, Method method, Ticket[] tickets) { switch (method) { case Method.Piter: { luckyCount = piter.PiterMethod(tickets); break; } case Method.Moscow: { luckyCount = moscow.MoscowMethod(tickets); break; } } return(luckyCount); }
/// <summary> /// Get menu for current task /// </summary> private void GetTaskMenu() { Moscow moscow = new Moscow(); Piter piter = new Piter(); BusinessLogic bl = new BusinessLogic(); Ticket ticket = new Ticket(DEFAULT_MIN); int luckyCount = 0; int leftrange = DEFAULT_MIN; int rightRange = DEFAULT_MAX; bool isOk = true; Console.WriteLine("Please, write the path to file, which contained method name."); Console.WriteLine("Example: ../../Files/Moscow.txt"); string path = this.PathInitializer(isOk); Method method; method = bl.SetMethod(path); try { Console.WriteLine("Enter the number of ticket from which we start:"); leftrange = int.Parse(Console.ReadLine()); Console.WriteLine("Enter the number of ticket which will the last:"); rightRange = int.Parse(Console.ReadLine()); if (leftrange <= 0) { isOk = false; Console.Beep(); Console.ForegroundColor = ConsoleColor.Red; throw new ArgumentOutOfRangeException("First ticket shouldn't be less than 1."); } if (rightRange >= 999999) { isOk = false; Console.Beep(); Console.ForegroundColor = ConsoleColor.Red; throw new ArgumentOutOfRangeException("Last ticket should be less than 999999"); } } catch (FormatException ex) { isOk = false; Console.Beep(); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("You should write a natural number." + ex.Message); } catch (ArgumentOutOfRangeException ex) { Console.WriteLine(ex.Message); } if (isOk) { Ticket[] tickets = bl.Initializer(leftrange, rightRange); luckyCount = bl.MethodInitialize(moscow, piter, luckyCount, method, tickets); Console.BackgroundColor = ConsoleColor.Green; Console.ForegroundColor = ConsoleColor.Black; Console.WriteLine($"You have {luckyCount} lucky tickets."); Console.ResetColor(); } Console.ReadKey(); }