Пример #1
0
        /// <summary>
        /// The method which contains the logic used within the Console app.
        /// </summary>
        /// <param name="args">The console arguments.</param>
        public static void Main(string[] args)
        {
            Console.Title = "Pig Translator 1.0";
            Console.WriteLine("Translate English to Pig-Latin!");
            string command;
            bool   exit = false;

            try
            {
                while (!exit)
                {
                    Console.WriteLine("Would you like to translate to English or Pig Latin? (Type 'help' for options)");
                    Console.Write("> ");
                    command = Console.ReadLine();
                    command = command.ToLower().Trim();
                    string[] commandWords = command.Split();
                    switch (commandWords[0])
                    {
                    case "pig":
                        ConsoleHelper.UserPrompt();
                        PigLatin pl = new PigLatin();
                        Console.WriteLine($"Translated Word: " + " " + pl.Translate(ConsoleHelper.ProcessString()));
                        break;

                    case "english":
                        ConsoleHelper.UserPrompt();
                        English e = new English();
                        Console.WriteLine($"Translated Word: " + " " + e.Translate(ConsoleHelper.ProcessString()));
                        break;

                    case "exit":
                        exit = true;
                        break;

                    case "clear":
                        Console.Clear();
                        break;

                    case "help":
                        Console.WriteLine("You can type 'Pig Latin', 'English', 'Exit' (To exit the program), or 'Clear' to clear the console.");
                        break;

                    default:
                        exit = false;
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Пример #2
0
        static void TranslateUserPhrase()
        {
            Console.Write("Welcome to the Pig Latin Translator! \nEnter a line to be translated: ");

            string input = Console.ReadLine();

            string[] parsedInput = input.Split(' ');

            for (int i = 0; i < parsedInput.Length; i++)
            {
                Console.Write(PigLatin.Translate(parsedInput[i]) + " ");
            }
            Console.WriteLine("\n");
        }