-
Notifications
You must be signed in to change notification settings - Fork 0
Week2 1 #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Week2 1 #4
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,21 +1,62 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
|
|
||
| namespace PigLatin | ||
| { | ||
| class Program | ||
| { | ||
| public static void Main() | ||
| public static void Main(string[] args) | ||
| { | ||
| // your code goes here | ||
|
|
||
| // leave this command at the end so your program does not close automatically | ||
| Console.ReadLine(); | ||
| //stores user input into string sentence | ||
| Console.WriteLine("Enter a sentence to convert to PigLatin:"); | ||
| string sentence = Console.ReadLine(); | ||
| //takes translated sentence from ToPigLatin and then writes it into console | ||
| string pigLatin = ToPigLatin(sentence); | ||
| Console.WriteLine(pigLatin.ToLower()); | ||
| } | ||
|
|
||
| public static string TranslateWord(string word) | ||
|
|
||
| //translates sentence | ||
| static string ToPigLatin (string sentence) | ||
| { | ||
| // your code goes here | ||
| return word; | ||
| //creates list of words that the translated words are added to | ||
| List<string> latin = new List<string>(); | ||
|
|
||
| //splits user entered input | ||
| foreach (string word in sentence.Split(' ')) | ||
| { | ||
| //checks position each vowel and y | ||
| int firstVowelIndex = word.IndexOfAny(new char[] {'A','E','I','O','U','a','e','i','o','u',}); | ||
| int firstYIndex = word.IndexOfAny(new char[] {'Y','y'}); | ||
|
|
||
| //checks if Y acts as vowel | ||
| if ((firstYIndex > 0) && (firstYIndex < firstVowelIndex) && (word.ToLower().Contains("y"))) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if firstYIndex is greater than 0 then the word must contain a 'y' so that last condition is not really needed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if firstYIndex is greater than 0 then the word must contain a 'y' so that last condition is not really needed. |
||
| { | ||
| string firstY = word.Substring(0, firstYIndex); | ||
| string restY = word.Substring(firstYIndex); | ||
| latin.Add(restY + firstY + "ay"); | ||
| } | ||
| //checks if word contains normal vowel | ||
| else if (firstVowelIndex > 0) | ||
| { | ||
| string first = word.Substring(0, firstVowelIndex); | ||
| string rest = word.Substring(firstVowelIndex); | ||
| latin.Add(rest + first + "ay"); | ||
| } | ||
| //checks if y acts as vowel in word with no other vowels | ||
| else if (firstYIndex > 0) | ||
| { | ||
| string firstY = word.Substring(0, firstYIndex); | ||
| string restY = word.Substring(firstYIndex); | ||
| latin.Add(restY + firstY + "ay"); | ||
| } | ||
| //checks if word starts with vowel or contains only consonents | ||
| else | ||
| { | ||
| latin.Add(word + "yay"); | ||
| } | ||
| } | ||
| //joins translated words together | ||
| return string.Join(" ", latin); | ||
| } | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dont see the tests.