//--------------------methods that satisfy contract with interface--------------------- public List <int> PlayFiveNumbers(string declareRandomOrManually) { const int maxLimitOfNumbers = 45; const int howManyNumbers = 5; //By For-Looping i fill my list for (int i = 0; i < howManyNumbers; i++) { //By Do-While-Looping i manage to fill my list with unique numbers do { //procedure goes on based on if i wish random numbers or numbers i manually insert switch (declareRandomOrManually) { case "random": Number = r.Next(1, maxLimitOfNumbers + 1); // by using next i decide the field of numbers break; case "manually": Console.Write($"Write {i + 1} number:"); // try-catch all possible exceptions try { Number = int.Parse(Console.ReadLine()); } catch (Exception) { Console.WriteLine("Please enter an integer number!"); } // i control the field of the numbers by using this while-loop while (Number < 1 || Number > maxLimitOfNumbers) { Console.Write("Number must be {0}-{1}. Try again:", 1, maxLimitOfNumbers); //try-catch all possible exceptions try { Number = int.Parse(Console.ReadLine()); } catch (Exception) { Console.WriteLine("Please enter an integer number!"); } } break; // empty default case for possible future use default: break; } } while (FiveNumbers.Contains(Number)); //when the number goes out of check for if unique, it is added to list FiveNumbers.Add(Number); } return(FiveNumbers); }
//-----------------------------------methods that satisfy contract with interface--------------------- //play five numbers public List <int> PlayFiveNumbers(string makeItNullForRandom) { Random r = new Random(); const int maxLimitOfNumbers = 45; const int howManyNumbers = 5; //By For-Looping i fill my list for (int i = 0; i < howManyNumbers; i++) { //By Do-While-Looping i manage to fill my list with unique numbers do { Number = r.Next(1, maxLimitOfNumbers + 1); // by using next i decide the field of numbers } while (FiveNumbers.Contains(Number)); //when the number goes out of check for if unique, it is added to list FiveNumbers.Add(Number); } FiveNumbers.Sort(); return(FiveNumbers); }