Tracks
/
C#
C#
/
Exercises
/
Split-Second Stopwatch
Split-Second Stopwatch

Split-Second Stopwatch

Medium

Introduction

You've always run for the thrill of it β€” no schedules, no timers, just the sound of your feet on the pavement. But now that you've joined a competitive running crew, things are getting serious. Training sessions are timed to the second, and every split second counts. To keep pace, you've picked up the Split-Second Stopwatch β€” a sleek, high-tech gadget that's about to become your new best friend.

Instructions

Your task is to build a stopwatch to keep precise track of lap times.

The stopwatch uses four commands (start, stop, lap, and reset) to keep track of:

  1. The current lap's tracked time
  2. Previously recorded lap times

What commands can be used depends on which state the stopwatch is in:

  1. Ready: initial state
  2. Running: tracking time
  3. Stopped: not tracking time
Command Begin state End state Effect
Start Ready Running Start tracking time
Start Stopped Running Resume tracking time
Stop Running Stopped Stop tracking time
Lap Running Running Add current lap to previous laps, then reset current lap
Reset Stopped Ready Reset current lap and clear previous laps
Edit via GitHub The link opens in a new window or tab
C# Exercism

Ready to start Split-Second Stopwatch?

Sign up to Exercism to learn and master C# with 62 concepts, 175 exercises, and real human mentoring, all for free.