public static void SearchLoop()
        {
            while (true)
            {
                PeriodicTable pt = new PeriodicTable();

                Console.Write("Select search mode [1: Atomic Number, 2: Symbol, 3: Name, 4: quit]: ");
                string mode = Console.ReadLine();
                if (mode == "4")
                {
                    return;
                }

                Console.Write("Search: ");
                string  search = Console.ReadLine();
                Element element;

                try
                {
                    switch (mode)
                    {
                    case "1":
                        element = pt.GetElement(Convert.ToInt32(search));
                        break;

                    case "2":
                        element = pt.GetElement(search);
                        break;

                    case "3":
                        element = pt.GetElementByName(search);
                        break;

                    default:
                        Console.WriteLine("ERROR: Invalid input detected.");
                        continue;
                    }
                }
                catch (System.Collections.Generic.KeyNotFoundException)
                {
                    // supress exception from being thrown
                    Console.WriteLine("ERROR: No matching element was found.");
                    continue;
                }
                Console.WriteLine("Atomic Number: {0}", element.AtomicNumber);
                Console.WriteLine("Name: {0}", element.Name);
                Console.WriteLine("Symbol: {0}", element.Symbol);
                Console.WriteLine("Weight: {0}M", element.AtomicWeight);
                Console.WriteLine();
            }
        }
Пример #2
0
        /// <summary>
        /// Every 2 digits of the 8 digit key are used as the atomic number of a periodic
        /// element to look up and store the integer value corresponding to the atomic
        /// weight.
        /// </summary>
        /// <param name="key">8 digit integer key</param>
        /// <returns>4 element integer array of integer atomic weights</returns>
        protected int[] GetShifts(int key)
        {
            string strKey = key.ToString();

            int[] wKey = new int[(int)Math.Ceiling((double)strKey.Length / 2)];
            for (double i = 0; i + 1 < strKey.Length; i = i + 2)
            {
                int aN = Convert.ToInt32(String.Concat(strKey[(int)i], strKey[(int)i + 1]));
                wKey[(int)Math.Floor(i / 2)] = (int)Math.Floor(pt.GetElement(aN).AtomicWeight);
            }
            return(wKey);
        }