Example #1
0
 public void DisplayResults(SockTracker sockTracker)
 {
     if (sockTracker.MatchingPairs.Count == 0)
     {
         Message.NoMatchingPairs(sockTracker.TotalNumberOfSocks());
     }
     else
     {
         Message.DisplayMatchingPairs(sockTracker.MatchingPairs.Count);
         foreach (var pair in sockTracker.MatchingPairs)
         {
             Console.WriteLine($"Pair of {pair} socks");
         }
         Console.WriteLine("\nPress enter to continue.");
         Console.ReadLine();
     }
     if (sockTracker.UnmatchedSocks.Count == 0)
     {
         Message.NoLeftOverSocks(sockTracker.TotalNumberOfSocks());
     }
     else
     {
         Message.DisplayLeftOverSocks(sockTracker.UnmatchedSocks.Count);
         foreach (var sock in sockTracker.UnmatchedSocks)
         {
             Console.WriteLine($"One {sock} sock");
         }
         Console.WriteLine($"\nPress enter to close the program.");
     }
 }
Example #2
0
        public SockTracker GetMatchingPairs(List <Color> sockPile)
        {
            var sockTracker = new SockTracker();

            sockTracker.MatchingPairs  = new List <Color>();
            sockTracker.UnmatchedSocks = new List <Color>();
            sockPile.Sort();
            while (sockPile.Count > 0)
            {
                if (sockPile.Count == 1)
                {
                    sockTracker.UnmatchedSocks.Add(sockPile[0]);
                }
                else
                {
                    if (sockPile[0] == sockPile[1])
                    {
                        sockTracker.MatchingPairs.Add(sockPile[0]);
                        sockPile.Remove(sockPile[1]);
                    }
                    else
                    {
                        sockTracker.UnmatchedSocks.Add(sockPile[0]);
                    }
                }
                sockPile.Remove(sockPile[0]);
            }
            return(sockTracker);
        }