2020-09-27 01:27:15 +03:00
|
|
|
## Check Instructions (#3)
|
|
|
|
|
2020-10-23 19:55:16 +03:00
|
|
|
This exercise further explores ranges, introduced in [Looping &
|
2020-11-18 20:35:46 +03:00
|
|
|
Ranges](https://stepik.org/lesson/104311/step/1), and shows how they can be used with check
|
2020-10-23 19:55:16 +03:00
|
|
|
instructions.
|
2020-09-27 01:27:15 +03:00
|
|
|
|
|
|
|
Create a class `Level` with two constructor arguments: `val range: IntRange`,
|
2020-12-12 02:30:51 +03:00
|
|
|
and `private var level: Int`. `level` has a default argument that is the bottom
|
|
|
|
value of `range`. The constructor should ensure that `level` is one of the
|
|
|
|
values in `range`.
|
2020-09-27 01:27:15 +03:00
|
|
|
|
|
|
|
Add a read-only `value` property that produces the value of `level`.
|
|
|
|
|
|
|
|
Add a function `up()` that increments `level` only if the result is within
|
2020-12-12 02:30:51 +03:00
|
|
|
`range`, and a function `down()` that decrements `level` only if the result is
|
|
|
|
within `range`. Finally, add a function `set(new: Int)` that first ensures that
|
|
|
|
`new` is within `range` and then assigns `new` to `level`.
|
2020-09-27 01:27:15 +03:00
|
|
|
|
2020-09-29 14:29:57 +03:00
|
|
|
`Level` is tested by the starter code in `main()`.
|
|
|
|
|
2020-10-12 13:11:53 +03:00
|
|
|
<sub> This task doesn't contain automatic tests,
|
|
|
|
so it's always marked as "Correct" when you run "Check".
|
|
|
|
Please compare your solution with the one provided! </sub>
|