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); } } }
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(); } }
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!"); } } }