예제 #1
0
        public void Run()
        {
            CorruptionChecksumLogic corruptionChecksumLogic = new CorruptionChecksumLogic();

            bool done = false;

            Console.WriteLine("This program will compute the corruption checksum " +
                              "\n(sum of difference of largest and smallest items in each row).");
            while (!done)
            {
                List <int[]> checksumNumberInput = new List <int[]>();
                Console.WriteLine("Enter space separated numbers (an array). Press ENTER to add a new row. Type a letter or empty row to end.");
                while (!done)
                {
                    string userInput = Console.ReadLine();

                    if (userInput == "" || !StringContainsOnlyNumbersAndSpaces(userInput))
                    {
                        Console.WriteLine("Done!");
                        done = true;
                    }
                    else
                    {
                        List <int> inputNumbers = new List <int>();
                        foreach (string s in userInput.Split(' '))
                        {
                            inputNumbers.Add(Convert.ToInt32(s));
                        }
                        checksumNumberInput.Add(inputNumbers.ToArray());
                    }
                }
                Console.WriteLine("The computed checksum is:");
                Console.WriteLine(corruptionChecksumLogic.GetChecksum(checksumNumberInput));
            }
            // end of program
            Console.ReadLine();
        }
예제 #2
0
 public void Initialize()
 {
     corruptionChecksumLogic = new CorruptionChecksumLogic();
 }