Skip to content

Conversation

EmmanuelBerkowicz
Copy link
Contributor

Add split-second-stopwatch exercise

Implement the split-second-stopwatch practice exercise with:

  • State management (ready/running/stopped)
  • Time tracking for current lap and total elapsed time
  • Lap functionality with previous laps history
  • Start, stop, reset operations with proper state validation
  • Error handling for invalid state transitions
  • Time formatting in HH:MM:SS format
  • Mock time advancement for testing

Includes reference solution, starter implementation, and comprehensive test suite covering all canonical data test cases.

pull request


Reviewer Resources:

Track Policies

Add split-second-stopwatch exercise

Implement the split-second-stopwatch practice exercise with:
- State management (ready/running/stopped)
- Time tracking for current lap and total elapsed time
- Lap functionality with previous laps history
- Start, stop, reset operations with proper state validation
- Error handling for invalid state transitions
- Time formatting in HH:MM:SS format
- Mock time advancement for testing

Includes reference solution, starter implementation, and comprehensive test suite covering all canonical data test cases.
@EmmanuelBerkowicz
Copy link
Contributor Author

Hey @kahgoh & @jagdish-15 ,

I'll review the failed checks.

But can you please confirm the structure of the code and content?

This is my first contribution to something like this, so my method was to copy an existing folder and modify to suit.

Thanks!
Emmanuel

Copy link
Member

@jagdish-15 jagdish-15 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This mostly looks good! But as you mentioned, you'll need to address the failed checks. The checkstyle errors aren't too serious, but the test failure suggests there might be an issue with either your test or the example (proof) solution.

Also, just a heads-up, you don’t need to manually copy everything over. You can use configlet to generate the basic structure and files for the exercise:

configlet 4.0.2
The official tool for managing Exercism language track repositories.

Usage:
  configlet.exe [global-options] <command> [command-options]

Commands:
  completion  Output a completion script for a given shell
  create      Add a new exercise, approach or article
  fmt         Format the exercise 'config.json' files
  generate    Generate Concept Exercise 'introduction.md' files from 'introduction.md.tpl' files
  info        Print some information about the track
  lint        Check the track configuration for correctness
  sync        Check or update Practice Exercise docs, metadata, and tests from 'problem-specifications'.
              Check or populate missing 'files' values for Concept/Practice Exercises from the track 'config.json'.
  uuid        Output new (version 4) UUIDs, suitable for the value of a 'uuid' key

Options for completion:
  -s, --shell <shell>             Choose the shell type (required)
                                  Allowed values: b[ash], f[ish], z[sh]

Options for create:
      --approach <slug>           The slug of the approach
      --article <slug>            The slug of the article
      --practice-exercise <slug>  The slug of the practice exercise
      --concept-exercise <slug>   The slug of the concept exercise
  -e, --exercise <slug>           Only operate on this exercise
  -o, --offline                   Do not update the cached 'problem-specifications' data
  -a, --author                    The author of the exercise, approach or article
  -d, --difficulty                The difficulty of the exercise (default: 1)

Options for fmt:
  -e, --exercise <slug>           Only operate on this exercise
  -u, --update                    Prompt to write formatted files
  -y, --yes                       Auto-confirm the prompt from --update

Options for generate:
  -e, --exercise <slug>           Only operate on this exercise
  -u, --update                    Prompt to write generated files
  -y, --yes                       Auto-confirm the prompt from --update

Options for info:
  -o, --offline                   Do not update the cached 'problem-specifications' data

Options for sync:
  -e, --exercise <slug>           Only operate on this exercise
  -o, --offline                   Do not update the cached 'problem-specifications' data
  -u, --update                    Prompt to update the unsynced track data
  -y, --yes                       Auto-confirm prompts from --update for updating docs, filepaths, and metadata
      --docs                      Sync Practice Exercise '.docs/introduction.md' and '.docs/instructions.md' files
      --filepaths                 Populate empty 'files' values in Concept/Practice exercise '.meta/config.json' files
      --metadata                  Sync Practice Exercise '.meta/config.json' metadata values
      --tests [mode]              Sync Practice Exercise '.meta/tests.toml' files.
                                  The mode value specifies how missing tests are handled when using --update.
                                  Allowed values: c[hoose], i[nclude], e[xclude] (default: choose)

Options for uuid:
  -n, --num <int>                 Number of UUIDs to output

Global options:
  -h, --help                      Show this help message and exit
      --version                   Show this tool's version information and exit
  -t, --track-dir <dir>           Specify a track directory to use instead of the current directory
  -v, --verbosity <verbosity>     The verbosity of output.
                                  Allowed values: q[uiet], n[ormal], d[etailed] (default: normal)

You can run ./gradlew test to check your tests and ./gradlew check for style issues.

And the author section in your exercise’s config.json, it should contain only your GitHub username, not even the usernames of maintainers and definitely not what you have right now.

Also, make sure to add the exercise to the root config.json as well. (You can see #2969 for an example, but if you do what I recommend below, you won't have to do it manually)

What I recommend is:

  • Save your stub, proof solution, and test file somewhere temporarily.
  • Delete the current folder for this exercise.
  • Then re-generate it using configlet. (If you try to generate it now, configlet will complain that the exercise already exists.)

You can set everything up manually if you really want to, but using configlet will make it easier and ensure you're not missing anything.

git add .
git commit -m "Add split-second-stopwatch exercise

Implement the split-second-stopwatch practice exercise with:
- State management (ready/running/stopped)
- Time tracking for current lap and total elapsed time
- Lap functionality with previous laps history
- Start, stop, reset operations with proper state validation
- Error handling for invalid state transitions
- Time formatting in HH:MM:SS format
- Mock time advancement for testing

Includes reference solution, starter implementation, and comprehensive test suite covering all canonical data test cases."
@jagdish-15
Copy link
Member

@EmmanuelBerkowicz

Now the exercise tests are passing, just add the files shown below:
Screenshot 2025-07-26 131045

You can copy them from any other existing exercise folder.

Once that’s done, this is good to go!

Gradle files added to new practice exercise.

Gradle/wrapper directories and files copied into split-second-stopwatch exercise as requested.
Prerequisites and difficulty updated in main config.json file.
config.json Outdated
"exceptions",
"if-else-statements"
],
"difficulty": 4
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the config.json, the exercises are arranged by difficulty level. So you'll need to move this one to the end of the level 4 exercises, right before the level 5 ones begin.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @jagdish-15, I think they are (mostly) sorted by difficulty, then exercise name.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jagdish-15 , @kahgoh
I didn't check this because I thought any arrangements or sorting would have been done during the configlet ftm --update.
(though to be fair, I wouldn't have been aware...)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jagdish-15 ,
sorry for all the hassle with this one, but can you please specify what you mean by update config.json?
I know you mentioned some steps earlier on in the pull request, but I did follow the method of using configlet.

Do you think I'll need to do so again?>

No worries @EmmanuelBerkowicz, by that I meant this, updating the position of this exercise in the config.json in the root folder (not the exercise folder)!

@jagdish-15
Copy link
Member

jagdish-15 commented Jul 28, 2025

@EmmanuelBerkowicz

Now the exercise tests are passing, just add the files shown below:
Screenshot 2025-07-26 131045

You can copy them from any other existing exercise folder.

Once that’s done, this is good to go!

You're still missing the gradlew and gradlew.bat files in the exercise directory (outside the gradle/wrapper folder). Could you add those as well? 🙂

@EmmanuelBerkowicz
Copy link
Contributor Author

@jagdish-15 ,
Sorry mate, I thought I had already added them!
Will do when I get home

@jagdish-15
Copy link
Member

@jagdish-15 ,
Sorry mate, I thought I had already added them!
Will do when I get home

No worries!

@kahgoh
Copy link
Member

kahgoh commented Jul 29, 2025

The lint is failing in the CI:

> Task :practice:split-second-stopwatch:processTestResources NO-SOURCE
> Task :practice:split-second-stopwatch:testClasses
Error: eckstyle] [ERROR] /home/runner/work/java/java/exercises/practice/split-second-stopwatch/.meta/src/reference/java/SplitSecondStopwatch.java:1: File does not end with a newline. [NewlineAtEndOfFile]

> Task :practice:split-second-stopwatch:checkstyleMain FAILED

> Task :practice:square-root:compileJava
  (source = /home/runner/work/java/java/exercises/practice/square-root/.meta/src/reference/java/SquareRoot.java)

> Task :practice:square-root:processResources NO-SOURCE
> Task :practice:square-root:classes
> Task :practice:square-root:copyTestsFilteringIgnores
Error: eckstyle] [ERROR] /home/runner/work/java/java/exercises/practice/split-second-stopwatch/src/test/java/SplitSecondStopwatchTest.java:1: File does not end with a newline. [NewlineAtEndOfFile]

If you want to run the check locally, try running ./gradlew check.

@EmmanuelBerkowicz
Copy link
Contributor Author

I'm sorry @kahgoh , but I'm a bit stuck here.
I've tried a few different things to fix this, like running git renormalize commands and manually adding spaces to the end of each file and updating the line format settings in intelliJ before running the gradle test, but they all give me the same error.

I'm probably overlooking something simple, but I'm a bit stuck and would appreciate a hint :)

Copy link
Member

@kahgoh kahgoh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry @kahgoh , but I'm a bit stuck here. I've tried a few different things to fix this, like running git renormalize commands and manually adding spaces to the end of each file and updating the line format settings in intelliJ before running the gradle test, but they all give me the same error.

I'm probably overlooking something simple, but I'm a bit stuck and would appreciate a hint :)

Just need to put a blank line at the end of the file ;) I've added them as suggestions below

@jagdish-15
Copy link
Member

Now the checkstyle errors have been taken care of, now the only thing remaining is the config.json, after that is also updated, we can finally merge it.

@EmmanuelBerkowicz
Copy link
Contributor Author

@jagdish-15 ,
sorry for all the hassle with this one, but can you please specify what you mean by update config.json?
I know you mentioned some steps earlier on in the pull request, but I did follow the method of using configlet.

Do you think I'll need to do so again?>

@jagdish-15
Copy link
Member

Do you think I'll need to do so again?>

No, you won’t need to redo the configuration. What I meant in my earlier message is that we just need to update the position of the exercise in the config.json file located in the root folder.

I’ve also unresolved the conversation above where we discussed this earlier, so you can refer back to it easily!

main config.json updated to reorder new practice exercise.
@jagdish-15 jagdish-15 merged commit 342b6a8 into exercism:main Jul 31, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants