예제 #1
0
        public static void Main()
        {
            RepeatCounter countMe = new RepeatCounter();

            Console.WriteLine("please enter a sentence:");
            string sentence = Console.ReadLine();

            Console.WriteLine("please enter a word: ");
            string word  = Console.ReadLine();
            bool   valid = countMe.Validator(word);

            if (valid == false)
            {
                Console.WriteLine("The word you entered is not a word.");
            }
            else if (countMe.ContainsWord(sentence, word) && (countMe.HowMany(sentence, word)) > 0)
            {
                int num = countMe.HowMany(sentence, word);
                Console.WriteLine("The sentence '" + sentence + "' contains " + num + " instances of the word '" + word + "'.");
            }
            else
            {
                Console.WriteLine("There are no instances of " + word + " in your sentence.");
            }
        }
예제 #2
0
 //Checks and returns word count in user sentence
 public static void ShowWordCount(RepeatCounter repeatCounter)
 {
     if (repeatCounter.ContainsWord())
     {
         int wordCount = repeatCounter.WordRepeatCount();
         Console.WriteLine(repeatCounter.WordInput + " shows ups " + wordCount + " times in your sentence");
     }
     else
     {
         Console.WriteLine("The word you entered cannot be found in the sentence you entered. Sorry!");
     }
 }