예제 #1
0
        static void Main()
        {
            Console.WriteLine("Give me a word to search.");
            string inputtedWord = Console.ReadLine();

            Console.WriteLine("Give me a sentence to search for the word.");
            string inputtedSentence = Console.ReadLine();

            RepeatCounter newWord = new RepeatCounter(inputtedWord);

            newWord.SetSentence(inputtedSentence);

            Console.WriteLine(newWord.GetWord() + " occured " + newWord.SearchWord() + " times.");
        }
예제 #2
0
        public static void InitApp()
        {
            Console.Clear();
            Console.Write("Please enter a sentence:");
            string userString = Console.ReadLine();

            Console.Write("Enter the word you'd like to count:");
            string userWord = Console.ReadLine();

            RepeatCounter newRepeat = new RepeatCounter(userString, userWord);

            newRepeat.CountWord();
            newRepeat.Results(newRepeat);
        }
예제 #3
0
        public static void Main()
        {
            Console.WriteLine(
                @"                Hello, and welcome to my program!
              Today we're going to scan a given sentence
              to see if (and how many times) a particular
              sequence of letters or symbols in it occurs.
              
      First, give me a series of letters, numbers, or symbols to scan.");

            string templateString = Console.ReadLine();

            Console.WriteLine(
                @"                
              
      Next: give me a series of letters numbers or symbols to scan for.");
            string scanString = Console.ReadLine();

            RepeatCounter scanner = new RepeatCounter(templateString, scanString);

            Console.WriteLine(scanner.CountOccurrences());
        }
예제 #4
0
        public void Results(RepeatCounter newRepeat)
        {
            Console.Clear();

            if (newRepeat.WordCount == 1)
            {
                Console.WriteLine("The word " + newRepeat.UserWord + " is in your sentence " + newRepeat.WordCount + " time.");
            }
            else if (newRepeat.WordCount == 0)
            {
                Console.WriteLine("Sorry, we couldn't find any instances of " + newRepeat.UserWord + " in your sentence.");
            }
            else
            {
                Console.WriteLine("The word " + newRepeat.UserWord + " is in your sentence " + newRepeat.WordCount + " times.");
            }

            Console.WriteLine("=========================================");
            Console.WriteLine("Please enter one of the numbers below:");
            Console.WriteLine("1. Check another word in my sentence.");
            Console.WriteLine("2. Start over with a new sentence.");
            Console.WriteLine("3. Exit Application.");
            string userChoice = Console.ReadLine();

            if (userChoice == "1")
            {
                CheckAnother(newRepeat);
            }
            else if (userChoice == "2")
            {
                RepeatCounter.InitApp();
            }
            else
            {
                Environment.Exit(0);
            }
        }
예제 #5
0
        public static int PerformWordCount(RepeatCounter newRepeatCounter)
        {
            string sentence   = newRepeatCounter.GetSentence();
            string chosenWord = newRepeatCounter.GetChosenWord();

            int wordTotal = 0;

            char[]   delimiterChars = { ' ', ',', '.', ':', '!', '\t' };
            string[] words          = sentence.Split(delimiterChars);

            for (int x = 0; x < words.Length; x++)
            {
                if (words[x] == chosenWord)
                {
                    wordTotal++;
                }
                else
                {
                }
            }

            newRepeatCounter.SetWordCount(wordTotal);
            return(wordTotal);
        }
예제 #6
0
        public void CountOccurrences__ReturnsCountOfInstancesIncludingFilterConditions_Two()
        {
            RepeatCounter counter = new RepeatCounter("cat in a cat bag", "cat");

            Assert.AreEqual("Your search string occurs: 2 times in the host string.", counter.CountOccurrences());
        }
예제 #7
0
        public void ValidInputFullWord_True()
        {
            bool output = RepeatCounter.ValidInput("brain");

            Assert.AreEqual(true, output);
        }
예제 #8
0
        public void EmptyInput_False()
        {
            bool output = RepeatCounter.ValidInput(" ");

            Assert.AreEqual(false, output);
        }
예제 #9
0
        public void NumberInWord_False()
        {
            bool output = RepeatCounter.ValidInput("br4in");

            Assert.AreEqual(false, output);
        }
예제 #10
0
        public void SpecialCharacters_False()
        {
            bool output = RepeatCounter.ValidInput("br@in");

            Assert.AreEqual(false, output);
        }
예제 #11
0
 public int Count(bool caseSensitive)
 {
     return(RepeatCounter.Count(_word, _wordList, caseSensitive));
 }