//methode for adding new words to the file static void AddTranslation(VocabularyManager vocabularyList) { bool enteredCorrectly = true; bool validInput = true; string[] languageArray = vocabularyList.GetLanguages(); string[] newTranslations = new string[languageArray.Length]; int numberOfNewWords; //asking for number of new words Console.WriteLine("Wie viele neue Wörter wollen sie hinzufügen"); do { enteredCorrectly = true; if (!int.TryParse(Console.ReadLine(), out numberOfNewWords)) { Console.WriteLine("Ungültige Eingabe. Bitte Wiederholen"); enteredCorrectly = false; } } while (!enteredCorrectly); //Big for-loop for adding new words for (int i = 0; i < numberOfNewWords; i++) { do { //input the translations of the word for (int j = 0; j < languageArray.Length; j++) { Console.WriteLine("Wort in {0} eingeben", languageArray[j]); newTranslations[j] = Console.ReadLine(); } //user checks input Console.WriteLine("\nKontrollieren sie ihre Eingabe."); Console.WriteLine("W - Eingabe Widerholen"); Console.WriteLine("E - Eingabe Bestätigen"); Console.WriteLine("A - Eingabe Abbrechen"); Console.WriteLine("Ihre erste eingabe lautet:\n"); //Output languages and input words foreach (var language in languageArray) { Console.Write(language.PadRight(20, ' ')); } Console.WriteLine(); foreach (var word in newTranslations) { Console.Write(word.PadRight(20, ' ')); } Console.WriteLine(); do { //user decide if input is correct string choice = Console.ReadLine(); switch (choice) { case "W": enteredCorrectly = false; validInput = true; break; case "w": enteredCorrectly = false; validInput = true; break; case "E": enteredCorrectly = true; validInput = true; break; case "e": enteredCorrectly = true; validInput = true; break; case "A": Console.Clear(); return; case "a": Console.Clear(); return; default: Console.WriteLine("Ungültige Eingabe. Bitte Wiederholen"); validInput = false; break; } } while (!validInput); } while (!enteredCorrectly); //creating new translation and add new Translation to the list Translator translation = new Translator(newTranslations, languageArray); try { vocabularyList.AddNewWordsToList(translation); vocabularyList.AddWordsToCSV(filePath, newTranslations); } catch (Exception) { Console.WriteLine("Der Dienst ist momentan nicht verfügbar.."); } } //Asking for other new words Console.WriteLine("\nWollen sie noch weitere Wörter hinzufügen schreiben sie ja"); Console.WriteLine("Ansonsten beliebige Taste und enter drücken"); if (Console.ReadLine() == "ja" || Console.ReadLine() == "Ja") { AddTranslation(vocabularyList); Console.Clear(); } Console.Clear(); }
static void VocabularyTest(VocabularyManager vocabularyList) { int userLang1; int userLang2; int choice; string tippWord; bool successChoice; bool successLanguage; bool translationSuccess; //decision which language to learn Console.WriteLine("Bitte beachten Sie die Groß- und Kleinschreibung der eingegebenen Wörter\n"); Console.WriteLine("Welche Sprache soll gelernt werden?"); //show existing languages in VocabularyList string[] translationArray = vocabularyList.GetLanguages(); for (int i = 0; i < translationArray.Length; i++) { Console.Write("{0} {1} ", i + 1, translationArray[i]); } //select the first language by Index Console.WriteLine("\nIndex der ersten Sprache"); do { successLanguage = true; if (!int.TryParse(Console.ReadLine(), out userLang1) || userLang1 > translationArray.Length || userLang1 < 0) { Console.WriteLine("Ungültige Eingabe. Bitte Wiederholen"); successLanguage = false; } } while (!successLanguage); //select the second language by Index Console.WriteLine("\nIndex der zweiten Sprache"); do { successLanguage = true; if (!int.TryParse(Console.ReadLine(), out userLang2) || userLang2 > translationArray.Length || userLang2 < 0) { Console.WriteLine("Ungültige Eingabe. Bitte Wiederholen"); successLanguage = false; } if (userLang2 == userLang1) { Console.WriteLine("Sie können nicht zweimal den die Selbe Sprache auswählen. Bitte Widerholen!"); successLanguage = false; } } while (!successLanguage); //choose the translation direction int languageIndex1 = userLang1 - 1; int languageIndex2 = userLang2 - 1; //choose direction of query Console.WriteLine("In welche Sprache möchten Sie übersetzen?\n1.{0}->{1} oder 2.{1}->{0}", translationArray[languageIndex1], translationArray[languageIndex2]); do { successChoice = true; if (!int.TryParse(Console.ReadLine(), out choice)) { Console.WriteLine("Ungültige Eingabe. Bitte Wiederholen"); successChoice = false; } if (choice != 1 && choice != 2) { Console.WriteLine("Ungültige Eingabe. Bitte Wiederholen"); successChoice = false; } } while (!successChoice); //select order if (choice == 1) { languageIndex1 = userLang1 - 1; languageIndex2 = userLang2 - 1; } if (choice == 2) { languageIndex1 = userLang2 - 1; languageIndex2 = userLang1 - 1; } //translation programm int counterRightWords = 0; string[] collectionWords = new string[2]; string randomWord; string randomWordTransl; translationSuccess = true; for (int i = 0; i < 10; i++) { //get a RandomWord and the right translation for training Console.Clear(); collectionWords = vocabularyList.RandomWord(languageIndex1, languageIndex2); randomWord = collectionWords[0]; randomWordTransl = collectionWords[1]; Console.WriteLine(); Console.WriteLine(randomWord); Console.WriteLine("Übersetzen Sie das Wort in {0}", translationArray[languageIndex2]); //For counting the wrong inputs int tippNumber = 0; //translation from User string inputWord = Console.ReadLine(); do { string placeHolder = ""; translationSuccess = true; //Checking input from user bool inputRight = vocabularyList.CheckingTranslation(randomWord, inputWord, languageIndex1, languageIndex2); if (inputRight) { //correct Translation Console.WriteLine("Wort ist richtig. Enter -> nächstes Wort"); Console.ReadLine(); counterRightWords++; translationSuccess = true; } else { //wrong Translation -> Tip Console.WriteLine("Das Wort ist falsch."); //if the word is less than 3 he will not get any tips if (randomWordTransl.Length >= 3) { tippNumber++; //first letters of the word as tip tippWord = randomWordTransl.Remove(randomWordTransl.Length - (randomWordTransl.Length - tippNumber)); for (int j = 0; j < randomWordTransl.Length - tippNumber; j++) { placeHolder += " _"; } Console.WriteLine("Hier ein Tipp: {0}{1} -> Versuchen Sie es erneut", tippWord, placeHolder); inputWord = Console.ReadLine(); inputRight = vocabularyList.CheckingTranslation(randomWord, inputWord, languageIndex1, languageIndex2); } if (inputRight) { Console.WriteLine("Wort ist richtig. Enter -> nächstes Wort"); Console.ReadLine(); counterRightWords++; translationSuccess = true; } //if the word is wrong after the third input it is considered wrong else if (tippNumber == 2) { Console.WriteLine("Das Wort ist falsch."); Console.ReadLine(); translationSuccess = true; } else { translationSuccess = false; } } } while (!translationSuccess); } //Result Console.WriteLine("Sie haben {0} von 10 Wörter richtig\n", counterRightWords); Console.ReadLine(); Console.Clear(); }