diff --git a/PigLatin/.vscode/launch.json b/PigLatin/.vscode/launch.json new file mode 100644 index 00000000..dbee6e56 --- /dev/null +++ b/PigLatin/.vscode/launch.json @@ -0,0 +1,28 @@ +{ + // Use IntelliSense to find out which attributes exist for C# debugging + // Use hover for the description of the existing attributes + // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md + "version": "0.2.0", + "configurations": [ + { + "name": ".NET Core Launch (console)", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "build", + // If you have changed target frameworks, make sure to update the program path. + "program": "${workspaceFolder}/bin/Debug/netcoreapp2.0/PigLatin.dll", + "args": [], + "cwd": "${workspaceFolder}", + // For more information about the 'console' field, see https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md#console-terminal-window + "console": "internalConsole", + "stopAtEntry": false, + "internalConsoleOptions": "openOnSessionStart" + }, + { + "name": ".NET Core Attach", + "type": "coreclr", + "request": "attach", + "processId": "${command:pickProcess}" + } + ,] +} \ No newline at end of file diff --git a/PigLatin/.vscode/tasks.json b/PigLatin/.vscode/tasks.json new file mode 100644 index 00000000..a705ed07 --- /dev/null +++ b/PigLatin/.vscode/tasks.json @@ -0,0 +1,15 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "build", + "command": "dotnet", + "type": "process", + "args": [ + "build", + "${workspaceFolder}/PigLatin.csproj" + ], + "problemMatcher": "$msCompile" + } + ] +} \ No newline at end of file diff --git a/PigLatin/PigLatin.cs b/PigLatin/PigLatin.cs index 702647dd..0230dd75 100644 --- a/PigLatin/PigLatin.cs +++ b/PigLatin/PigLatin.cs @@ -6,16 +6,88 @@ class Program { public static void Main() { - // your code goes here + TranslateWords(); + PlayAgain(); - // leave this command at the end so your program does not close automatically - Console.ReadLine(); - } - - public static string TranslateWord(string word) - { - // your code goes here - return word; + void TranslateWords() { + Console.WriteLine("Please type in a word or sentence and press the Enter key."); + string sentence = Console.ReadLine().ToLower(); + string[] words = sentence.Split(' '); + string[] translatedWords = new string[words.Length]; + for (int j = 0; j < words.Length; j++) + { + char[] vowels = { 'a', 'e', 'i', 'o', 'u', 'y',}; + string a = "a"; + string e = "e"; + string i = "i"; + string o = "o"; + string u = "u"; + string y = "y"; + string word = words[j]; + int wordLength = word.Length; + + if (word.Contains(a) || word.Contains(e) || word.Contains(i) || word.Contains(o) || word.Contains(u) || word.Contains(y)) + { + int firstVowelIndex = word.IndexOfAny(vowels); + string firstHalf = word.Substring(0, firstVowelIndex); + int secondHalfLength = wordLength - firstVowelIndex; + string secondHalf = word.Substring(firstVowelIndex, secondHalfLength); + if (firstVowelIndex == 0) + { + string composite = secondHalf + firstHalf + "yay"; + translatedWords[j] = composite; + } + else + { + string composite = secondHalf + firstHalf + "ay"; + translatedWords[j] = composite; + } + } + else + { + translatedWords[j] = word + "yay"; + } + + + // int firstVowelIndex = word.IndexOfAny(vowels); + // string firstHalf = word.Substring(0, firstVowelIndex); + // int secondHalfLength = wordLength - firstVowelIndex; + // string secondHalf = word.Substring(firstVowelIndex, secondHalfLength); + // if (firstVowelIndex == 0) + // { + // string composite = secondHalf + firstHalf + "yay"; + // translatedWords[j] = composite; + // } + // else + // { + // string composite = secondHalf + firstHalf + "ay"; + // translatedWords[j] = composite; + // } + } + string translatedSentence = String.Join(" ", translatedWords); + Console.WriteLine(translatedSentence); + } + + void PlayAgain() { + string[] yes = { Convert.ToString('y'), Convert.ToString('Y'), "yes", "Yes", "YES"}; + Console.WriteLine("Do you want to try again? [y/n]"); + for (int i = 0; i < yes.Length; i++) + { + string choice = Console.ReadLine(); + if (choice == yes[i]) + { + TranslateWords(); + PlayAgain(); + } + else + { + Console.WriteLine("Bye!"); + Environment.Exit(0); + } + } + } + + } } }