Implement a clock that handles times without dates.
Make a class that can store the time of day and display it in 24 hours format, also known as "HH:mm". For example, if we start the clock with 2 hours and 10 minutes it should display "02:10".
We want to be able to add minutes to the clock and have the clock display a valid time of day. For this exercise the date doesn't matter, only the time of day.
Now that the clock can add minutes, it should also be able to subtract them!
Once the clock can add and subtract minutes, we want to know that two instances of the clock are equal if they have the same time of day.
Consider making the clock instances immutable
- Try not to change the method signatures unless you think it's necessary
- You might want to override the ToString method for the class and format the time there
- Consider minutes and hours overflowing and underflowing
- There are test cases written but we encourage you to also write some if you need to
Replit lets us use a common environment that doesn't need local setup and can be shared! Because of some limitations with test projects in .Net core the run button doesn't do anything.
To run you can open a console (on the left toolbar you will find a section called Tools and you can open a console there, if there's not one open already). Once in the console you can run the unit tests by using:
dotnet testIf you want the tests to run continually as you do edits to the problem you can use:
dotnet watch testYou are welcome to use your own machine. You will need to be able to compile projects targeting .net core 6. You can download the SDK here and use your favorite code editor. To run tests:
dotnet testTo continually run tests:
dotnet watch test