рандом предложения

← разместить еще код

Расшаренный код:

using System;

namespace Strange_sentences
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("ЗДЕСЬ ТЕБЕ НУЖНО ПРОСТО ВВЕСТИ 4 СУЩЕСТВИТЕЛЬНЫХ");

            string[] words = new string[4];

            Console.WriteLine("слово №1: ");
            words[0] = Console.ReadLine();

            Console.WriteLine("слово №2: ");
            words[1] = Console.ReadLine();

            Console.WriteLine("слово №3:");
            words[2] = Console.ReadLine();

            Console.WriteLine("слово №4: ");
            words[3] = Console.ReadLine();

            words = ChangeWords(words);
            Console.WriteLine("ВОТ ЧТО СЕГОДНЯ ПРОИЗОЙДЕТ:");
            DoSentence(words[0], words[1], words[2], words[3]);
        }
        static string[] ChangeWords(string[] array)
        {
            string[] data = array;
            var random = new Random();
            for (int i = data.Length - 1; i >= 1; i--)
            {
                int j = random.Next(i + 1);
                var temp = data[j];
                data[j] = data[i];
                data[i] = temp;
            }
            return data;
        }

        static void DoSentence(string word1, string word2, string word3, string word4)
        {
            string adjective = CreateAdjective(word1);
            string noun = CreateNoun(word2);
            string verb = CreateVerb(word3);
            string addiction = CreateAddition(word4);
            Console.WriteLine(adjective + noun + verb + addiction);
        }

        static string CreateVerb(string word)
        {
            string result;
            if (word.Substring(word.Length - 1) == "а" || word.Substring(word.Length - 1) == "о"
                || word.Substring(word.Length - 1) == "е" || word.Substring(word.Length - 1) == "ь"
                || word.Substring(word.Length - 1) == "я")
                result = word.Remove(word.Length - 1);
            else result = word;
            return result + "ит ";
        }

        static string CreateAddition(string word)
        {
            string result;
            if (word.Substring(word.Length - 1) == "а" || word.Substring(word.Length - 1) == "о"
                || word.Substring(word.Length - 1) == "е" || word.Substring(word.Length - 1) == "ь"
                || word.Substring(word.Length - 1) == "я")
                result = word.Remove(word.Length - 1);
            else result = word;
            return "в " + result + "e.";
        }

        static string CreateAdjective(string word)
        {
            string result;
            if (word.Substring(word.Length - 1) == "а" || word.Substring(word.Length - 1) == "о"
                || word.Substring(word.Length - 1) == "е" || word.Substring(word.Length - 1) == "ь"
                || word.Substring(word.Length - 1) == "я")
                result = word.Remove(word.Length - 1);
            else result = word;

            if (result.Substring(result.Length - 1) == "л")
                return result + "ьный ";
            else return result + "ный ";
        }
        static string CreateNoun(string word)
        {
            return word + " ";
        }
    }
}