Exemplo n.º 1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Please write the name or path of the file to analyze");
            string filename = Console.ReadLine();

            string[] lines = FileReader.ReadFile(filename);

            DriverStore drivers = new DriverStore();

            foreach (string line in lines)
            {
                string[] separatedLines = line.Split(" ");

                ProgramOperation.DoOp(separatedLines, drivers);
            }

            drivers.PrintReport();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Function that executes the operation
        /// </summary>
        /// <param name="operationData">List of strings containing the data required for the operation</param>
        /// <param name="store">Object reference of the Driver Store</param>
        public static void DoOp(string[] operationData, DriverStore store)
        {
            if (operationData.Length == 2 && operationData[0].ToUpper() == "DRIVER")
            {
                store.AddDriver(new Driver(operationData[1]));
            }
            else if (operationData.Length == 5 && operationData[0].ToUpper() == "TRIP")
            {
                string driverName = operationData[1];
                if (store.HasDriver(driverName))
                {
                    DateTime startTime = DateTime.ParseExact(operationData[2], "HH:mm", CultureInfo.InvariantCulture);
                    DateTime endTime   = DateTime.ParseExact(operationData[3], "HH:mm", CultureInfo.InvariantCulture);
                    float    distance  = float.Parse(operationData[4], CultureInfo.InvariantCulture);

                    Trip newTrip = new Trip(startTime, endTime, distance);

                    if (5 <= newTrip.Speed && newTrip.Speed <= 100)
                    {
                        store.GetDriver(driverName).AddTrip(newTrip);
                    }
                }
            }
        }