示例#1
0
        static void Main(string[] args)
        {
            var chronometer = new Chronometer();

            string input;

            while ((input = Console.ReadLine()) != "exit")
            {
                var result = string.Empty;
                switch (input.ToLower())
                {
                case "start":
                    chronometer.Start();
                    break;

                case "stop":
                    chronometer.Stop();
                    break;

                case "reset":
                    chronometer.Reset();
                    break;

                case "laps":
                    var allLaps = chronometer.Laps;
                    if (allLaps.Count > 0)
                    {
                        for (int i = 0; i < allLaps.Count; i++)
                        {
                            var currentLap = allLaps[i];
                            result += $"{i}. {currentLap.ToString()}\r\n";
                        }
                    }
                    else
                    {
                        result = "Laps: no laps";
                    }
                    break;

                case "time":
                    result = chronometer.GetTime;
                    break;

                case "lap":
                    result = chronometer.Lap();
                    break;

                default:
                    result = "Invalid command.";
                    break;
                }

                if (result.Length != 0)
                {
                    Console.WriteLine(result);
                }
            }
        }
示例#2
0
        static void Main(string[] args)
        {
            Chronometer chronometer = new Chronometer();
            string      command     = Console.ReadLine();
            int         lapsCounter = 0;

            while (true)
            {
                switch (command)
                {
                case "start":
                    chronometer.Start();
                    break;

                case "stop":
                    chronometer.Stop();
                    break;

                case "reset":
                    chronometer.Reset();
                    break;

                case "lap":
                    Console.WriteLine($"{chronometer.Lap()}");
                    break;

                case "time":
                    Console.WriteLine($"{chronometer.GetTime}");
                    break;

                default:
                    break;
                }
                if (command == "laps")
                {
                    var laps = chronometer.Laps;

                    if (!laps.Any())
                    {
                        Console.WriteLine("Laps: no laps");
                    }

                    foreach (var lap in laps)
                    {
                        Console.WriteLine($"{lapsCounter}. {lap}");
                        lapsCounter++;
                    }
                }
                if (command == "exit")
                {
                    break;
                }
                command = Console.ReadLine();
            }
        }
示例#3
0
        static void Main(string[] args)
        {
            IChronometer chronometer = new Chronometer();

            string command = string.Empty;

            while ((command = Console.ReadLine().ToLower()) != "exit")
            {
                if (command == "start")
                {
                    chronometer.Start();
                }
                else if (command == "stop")
                {
                    chronometer.Stop();
                }
                else if (command == "lap")
                {
                    Console.WriteLine(chronometer.Lap());
                }
                else if (command == "laps")
                {
                    if (chronometer.Laps.Count == 0)
                    {
                        Console.WriteLine("Laps: no laps");
                        continue;
                    }

                    for (int i = 0; i < chronometer.Laps.Count; i++)
                    {
                        Console.WriteLine($"{i}. {chronometer.Laps[i]}");
                    }
                }
                else if (command == "time")
                {
                    if (chronometer.GetTime.Length > 3)
                    {
                        Console.WriteLine(chronometer.GetTime);
                    }
                    else
                    {
                        Console.WriteLine("The chronometer is not started!");
                    }
                }
                else if (command == "reset")
                {
                    chronometer.Reset();
                }
                else
                {
                    Console.WriteLine($"\"{command}\" is not a valid command!");
                }
            }
        }
示例#4
0
        public static void Main()
        {
            Chronometer chronometer = new Chronometer();

            while (true)
            {
                string input = Console.ReadLine();

                switch (input)
                {
                case "start":
                    Task.Run(() => chronometer.Start());
                    break;

                case "lap":
                    Task.Run(() =>
                    {
                        chronometer.Lap();
                        Console.WriteLine(chronometer.GetTime);
                    });
                    break;

                case "laps":
                    Task.Run(() =>
                    {
                        Console.WriteLine(chronometer.AllLaps());
                    });
                    break;

                case "reset":
                    Task.Run(() =>
                    {
                        chronometer.Reset();
                    });
                    break;
                }
            }
        }