Пример #1
0
        private static void ChangeRankMenu(Military mil)
        {
            while (true)
            {
                Console.WriteLine("Select new rank:");
                Console.WriteLine("0. Private");
                Console.WriteLine("1. Sergeant");
                Console.WriteLine("2. Major");
                Console.WriteLine("3. Colonel");
                int key;
                try { key = Convert.ToInt32(Console.ReadLine()); }
                catch (Exception e) { Console.Clear(); Console.WriteLine("The input must be a number between 0 and 3"); continue; }
                switch (key)
                {
                case 0: mil.ChangeRank(new Private(mil.Fullname)); break;

                case 1: mil.ChangeRank(new Sergeant(mil.Fullname)); break;

                case 2: mil.ChangeRank(new Major(mil.Fullname)); break;

                case 3: mil.ChangeRank(new Colonel(mil.Fullname)); break;

                default:
                {
                    Console.Clear();
                    Console.WriteLine("The input must be a number between 0 and 3");
                    continue;
                }
                }
                Console.Clear();
                break;
            }
        }