/// <summary>
        /// Calculates final time till all customers are served.
        /// </summary>
        /// <param name="registerSet"></param>
        /// <param name="grocery"></param>
        /// <returns></returns>
        private static int finaltime(RegisterFunctions registerSet, Grocery grocery)
        {
            int time = 1;

            while (!(customerQueue.Count() == 0) || registerSet.getRegisterstatus())
            {
                List <Customer> customersAtSameTime = new List <Customer>();
                GroceryHelper.getCustomersArrivingSameTime(customersAtSameTime, time);
                customersAtSameTime.Sort();
                registerSet.serviceCustomer(customersAtSameTime);
                int index = 0;
                while (index < registerSet.getRegisterList().Count())
                {
                    Queue <Customer> customer = registerSet.getRegisterList()[index].getCustomers();
                    if (index == registerSet.getRegisterList().Count() - 1)
                    {
                        GroceryHelper.traineeServe(customer);
                    }
                    else
                    {
                        GroceryHelper.expertServe(customer);
                    }
                    index++;
                }
                time++;
            }
            return(time);
        }
        static void Main(string[] args)
        {
            Grocery           grocery     = GroceryHelper.readFromfile(args);
            RegisterFunctions registerSet = grocery.getRegisterFunctons();
            int time = finaltime(registerSet, grocery);

            Console.WriteLine("Finished at: t = " + time + " minutes");
            // Console.ReadLine();
        }
        /// <summary>
        /// Building Inputs from the file using Stream reader.
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>
        public static Grocery readFromfile(string [] args)
        {
            Grocery           grocery           = null;
            RegisterFunctions registerFunctions = null;
            StreamReader      streamReader      = null;
            string            line = " ";
            int firstline          = 0;

            try
            {
                streamReader = new StreamReader(args[0]);
            }
            catch (FileNotFoundException e)
            {
                Console.WriteLine("File Not Found" + e.Message);
                Environment.Exit(-1);
            }
            try
            {
                while ((line = streamReader.ReadLine()) != null)
                {
                    if (firstline == 0)
                    {
                        int noOfRegisters = Convert.ToInt32(line);
                        registerFunctions = new RegisterFunctions(noOfRegisters);
                    }
                    else
                    {
                        Customer customer = buildCustomer(line);
                        customerQueue.Enqueue(customer);
                    }
                    firstline++;
                }
                grocery = new Grocery(registerFunctions);
            }
            catch (IOException e)
            {
                Console.WriteLine("Error reading Input" + e.Message);
                Environment.Exit(-1);
            }
            return(grocery);
        }
 public Grocery(RegisterFunctions registerTotal)
 {
     this.registerTotal = registerTotal;
 }