Example #1
0
        static void Main(string[] args)
        {
            // Some arrays and collections used in this demo app might not be fully encapsulated.
            // This is justifiable since this app is used for demonstration only.
            //
            // Some commented code is written for code extensibility, for which implementation is not requested.

            ParkingLot lot        = new ParkingLot();
            bool       formatFlag = false;
            int        selection  = 0;

            PrintState(lot);
            do
            {
                try
                {
                    Console.Write("Enter a car number: ");
                    selection = Int32.Parse(Console.ReadLine());
                    Console.WriteLine();
                    formatFlag = true;
                    if (lot.Queue(selection) == false)
                    {
                        Console.WriteLine("Invalid Input - Car Already Pending or Parked. ");
                        formatFlag = false;
                    }
                }
                catch (FormatException)
                {
                    Console.WriteLine("Invalid Input - Format Error. ");
                    formatFlag = false;
                }
                catch (ArgumentException)
                {
                    Console.WriteLine("Invalid Input - Car Not Found. ");
                    formatFlag = false;
                }
            }while (formatFlag == false);
            for (int i = 0; i < 2; i++)
            {
                Console.Clear();
                PrintState(lot);
                lot.Queue();
                Console.WriteLine("Press any key to continue... ");
                Console.ReadKey();
            }
            Console.Clear();
            PrintState(lot);
        }