Added marker text for exercises without automatic tests
This commit is contained in:
parent
608a539b86
commit
d184aed537
|
@ -12,4 +12,8 @@ interactWithCrocodile(honestlyDuck.crocodile)
|
|||
|
||||
Modify the solution to that exercise using class delegation so you can call a
|
||||
function `interactWithCrocodile(honestlyDuck)`. Make the `IAmHonestlyDuck`
|
||||
`crocodile` parameter `private` so you *cannot* expose `field`.
|
||||
`crocodile` parameter `private` so you *cannot* expose `field`.
|
||||
|
||||
<sub> This task doesn't contain the automatic tests,
|
||||
it's always marked as "Correct" on "Check".
|
||||
Please compare your solution with the provided one! </sub>
|
|
@ -8,4 +8,8 @@ Create a class `AImpl` that implements `A` and traces `"A.foo()"` for `foo()`
|
|||
and `"A.bar()"` for `bar()`. Create a similar implementation `BImpl` that
|
||||
implements `B`. Now create a class `Delegation` that delegates to both `A` and
|
||||
`B`. IntelliJ or the compiler will guide you in resolving the resulting
|
||||
issues.
|
||||
issues.
|
||||
|
||||
<sub> This task doesn't contain the automatic tests,
|
||||
it's always marked as "Correct" on "Check".
|
||||
Please compare your solution with the provided one! </sub>
|
|
@ -24,4 +24,8 @@ containing an anonymous inner class that implements `VendorFactory`.
|
|||
|
||||
Now write a standalone function `consumer(factory: VendorFactory)` that uses
|
||||
`factory` to create a `Vendor`. Use that `Vendor` to call `pencil()` and
|
||||
`pen()`. The starter code in `main()` will validate your solution.
|
||||
`pen()`. The starter code in `main()` will validate your solution.
|
||||
|
||||
<sub> This task doesn't contain the automatic tests,
|
||||
it's always marked as "Correct" on "Check".
|
||||
Please compare your solution with the provided one! </sub>
|
|
@ -23,4 +23,8 @@ them both `private` constructors with no arguments. Each class should contain a
|
|||
constructor. Each companion object contains a `const val max` that is used
|
||||
within `move()`. The definitions of `playGame()` and `main()` are provided;
|
||||
complete the code in `Checkers` and `Chess` so it satisfies the tests in
|
||||
`main()`.
|
||||
`main()`.
|
||||
|
||||
<sub> This task doesn't contain the automatic tests,
|
||||
it's always marked as "Correct" on "Check".
|
||||
Please compare your solution with the provided one! </sub>
|
|
@ -55,4 +55,8 @@ steps during object creation. `applyForAccount()` begins the creation of a new
|
|||
the `Account`, and `completeAccount()` takes an `ID`, adds an account `number`,
|
||||
and moves the `Account` from the `applied` to the `accounts` list.
|
||||
|
||||
The starter code in `main()` will validate your solution.
|
||||
The starter code in `main()` will validate your solution.
|
||||
|
||||
<sub> This task doesn't contain the automatic tests,
|
||||
it's always marked as "Correct" on "Check".
|
||||
Please compare your solution with the provided one! </sub>
|
|
@ -7,4 +7,8 @@ function. The `trace` argument is the class name and function; for example
|
|||
|
||||
Now write a function `checkAndCall(b: Base)` so that it calls the polymorphic
|
||||
member function, then uses a `when` to downcast and call the extended-interface
|
||||
functions.
|
||||
functions.
|
||||
|
||||
<sub> This task doesn't contain the automatic tests,
|
||||
it's always marked as "Correct" on "Check".
|
||||
Please compare your solution with the provided one! </sub>
|
|
@ -9,4 +9,8 @@ There's a second, more dynamic form of `filterIsInstance()`, which takes a
|
|||
*class object* as a parameter. Pass `Dog::class.java` as the argument to
|
||||
`filterIsInstance()`, with the rest of the expression as described in the
|
||||
previous paragraph. How is this version of `filterIsInstance()` different from
|
||||
the version that uses a generic argument?
|
||||
the version that uses a generic argument?
|
||||
|
||||
<sub> This task doesn't contain the automatic tests,
|
||||
it's always marked as "Correct" on "Check".
|
||||
Please compare your solution with the provided one! </sub>
|
|
@ -14,4 +14,8 @@ Create a duplicate hierarchy from an interface `Animal2`, but in this case make
|
|||
`Beetle2`. In `main()`, create a `List` of `Animal2` objects and call `move()`
|
||||
for each one.
|
||||
|
||||
Compare the type-checked hierarchy to the polymorphic hierarchy.
|
||||
Compare the type-checked hierarchy to the polymorphic hierarchy.
|
||||
|
||||
<sub> This task doesn't contain the automatic tests,
|
||||
it's always marked as "Correct" on "Check".
|
||||
Please compare your solution with the provided one! </sub>
|
|
@ -2,4 +2,8 @@
|
|||
|
||||
Add a `hamster()` member function to `LocalInnerClasses.kt` with a local `val
|
||||
poke = "Squeak"` that returns an object of an anonymous inner class that
|
||||
extends `Pet`, with a `speak()` that produces `poke + home()`.
|
||||
extends `Pet`, with a `speak()` that produces `poke + home()`.
|
||||
|
||||
<sub> This task doesn't contain the automatic tests,
|
||||
it's always marked as "Correct" on "Check".
|
||||
Please compare your solution with the provided one! </sub>
|
|
@ -15,4 +15,8 @@ function `f()` that returns `"Any-based"`.
|
|||
|
||||
Add a member function `manifest()` that produces a `String` containing the
|
||||
properties `contains` and `label` and the output of `f()`. The starter code in
|
||||
`main()` tests your solution.
|
||||
`main()` tests your solution.
|
||||
|
||||
<sub> This task doesn't contain the automatic tests,
|
||||
it's always marked as "Correct" on "Check".
|
||||
Please compare your solution with the provided one! </sub>
|
|
@ -27,4 +27,8 @@ Now make `Container` inherit from `Iterable<T>`, and add a function called
|
|||
from `Iterator<T>`. Add a standalone function `<T> traceAll2(ib: Iterable<T>)`
|
||||
that produces the same behavior as `traceAll()`.
|
||||
|
||||
The starter code contains a `main()` with tests to verify your code.
|
||||
The starter code contains a `main()` with tests to verify your code.
|
||||
|
||||
<sub> This task doesn't contain the automatic tests,
|
||||
it's always marked as "Correct" on "Check".
|
||||
Please compare your solution with the provided one! </sub>
|
|
@ -5,4 +5,8 @@ In `FillIt.kt`, `State` is only used to determine when there are no more
|
|||
returning a `Boolean` from `turn()`. Once you have that working, add a third
|
||||
player by changing `enum class Mark { Blank, X ,O }` to `enum class Mark {
|
||||
Blank, X, Y, Z }`. In `turn()`, use a `when` expression to move to the next
|
||||
`player` value.
|
||||
`player` value.
|
||||
|
||||
<sub> This task doesn't contain the automatic tests,
|
||||
it's always marked as "Correct" on "Check".
|
||||
Please compare your solution with the provided one! </sub>
|
|
@ -1,4 +1,8 @@
|
|||
## Nested Classes (#2)
|
||||
|
||||
In `NestedHouse.kt`, add two `Drawer`s to `Closet` and a `Bathtub` to
|
||||
`Bathroom`.
|
||||
`Bathroom`.
|
||||
|
||||
<sub> This task doesn't contain the automatic tests,
|
||||
it's always marked as "Correct" on "Check".
|
||||
Please compare your solution with the provided one! </sub>
|
|
@ -1,4 +1,8 @@
|
|||
## Nested Classes (#3)
|
||||
|
||||
"Unpack" the nested classes in `NestedHouse.kt` by turning each nested class
|
||||
into a global class.
|
||||
into a global class.
|
||||
|
||||
<sub> This task doesn't contain the automatic tests,
|
||||
it's always marked as "Correct" on "Check".
|
||||
Please compare your solution with the provided one! </sub>
|
|
@ -10,4 +10,8 @@ the `simpleName` of the specific subclass.
|
|||
`upgrade()` and `meal()` functions which forward their actions to the `Seat`
|
||||
object.
|
||||
|
||||
Bonus (Challenging): Why can't you use delegation for `seat` in `Ticket`?
|
||||
Bonus (Challenging): Why can't you use delegation for `seat` in `Ticket`?
|
||||
|
||||
<sub> This task doesn't contain the automatic tests,
|
||||
it's always marked as "Correct" on "Check".
|
||||
Please compare your solution with the provided one! </sub>
|
|
@ -4,4 +4,8 @@ Create a file-level `private fun f()` and `private val p`. The starter code in
|
|||
`main()` will show you how to write these. Now duplicate `f()` and `p` inside
|
||||
`object Space` and again in `private object Space2`, and get these to work
|
||||
according to the code in `main()`. Notice the changes required to make `f()`
|
||||
available in `main()`. Compare the different approaches.
|
||||
available in `main()`. Compare the different approaches.
|
||||
|
||||
<sub> This task doesn't contain the automatic tests,
|
||||
it's always marked as "Correct" on "Check".
|
||||
Please compare your solution with the provided one! </sub>
|
|
@ -3,4 +3,8 @@
|
|||
Add more nesting to `ObjectNesting.kt`. Inside both the `Nested` objects, add
|
||||
another `Nested` object that looks the same as its enclosing `Nested`, with the
|
||||
same name and property, and an appropriate `String` for `a`. The code in
|
||||
`main()` provides tests. Notice how the namespaces work.
|
||||
`main()` provides tests. Notice how the namespaces work.
|
||||
|
||||
<sub> This task doesn't contain the automatic tests,
|
||||
it's always marked as "Correct" on "Check".
|
||||
Please compare your solution with the provided one! </sub>
|
|
@ -19,4 +19,8 @@ that returns their class name.
|
|||
|
||||
Now define an `object MonkeysVsSnakes` which is an `AdventureGame`, using the
|
||||
various `create()` functions to initialize it. `populate()` only needs to add
|
||||
one `Monkey` and one `Snake`. The predefined `main()` will test your code.
|
||||
one `Monkey` and one `Snake`. The predefined `main()` will test your code.
|
||||
|
||||
<sub> This task doesn't contain the automatic tests,
|
||||
it's always marked as "Correct" on "Check".
|
||||
Please compare your solution with the provided one! </sub>
|
|
@ -1,4 +1,8 @@
|
|||
## Type Checking (#1)
|
||||
|
||||
Modify `TypeCheck3.kt` by moving `rotate()` into `Shape` and returning `Shape`
|
||||
to an `interface`. Notice how `turn()` becomes much cleaner.
|
||||
to an `interface`. Notice how `turn()` becomes much cleaner.
|
||||
|
||||
<sub> This task doesn't contain the automatic tests,
|
||||
it's always marked as "Correct" on "Check".
|
||||
Please compare your solution with the provided one! </sub>
|
|
@ -4,4 +4,8 @@ Add a `DecomposableBottle` to both `BeverageContainer2.kt` (remove `recycle()`)
|
|||
and `BeverageContainer3.kt`. `DecomposableBottle`'s recycling `String` is
|
||||
"Decomposition tank".
|
||||
|
||||
Notice the different experience between the two examples.
|
||||
Notice the different experience between the two examples.
|
||||
|
||||
<sub> This task doesn't contain the automatic tests,
|
||||
it's always marked as "Correct" on "Check".
|
||||
Please compare your solution with the provided one! </sub>
|
|
@ -5,4 +5,8 @@ modifications to other components). Change `basic()` to use a `when`
|
|||
expression.
|
||||
|
||||
What does this gain you, since the `else` clauses in the `when` expressions
|
||||
still make sense?
|
||||
still make sense?
|
||||
|
||||
<sub> This task doesn't contain the automatic tests,
|
||||
it's always marked as "Correct" on "Check".
|
||||
Please compare your solution with the provided one! </sub>
|
|
@ -11,4 +11,8 @@ current element in `items`. Each call to `next()` produces the current element
|
|||
and increments `index`. When there are no more `items`, `next()` returns
|
||||
`null`.
|
||||
|
||||
The code in `main()` tests your solution.
|
||||
The code in `main()` tests your solution.
|
||||
|
||||
<sub> This task doesn't contain the automatic tests,
|
||||
it's always marked as "Correct" on "Check".
|
||||
Please compare your solution with the provided one! </sub>
|
|
@ -9,4 +9,8 @@ square brackets.
|
|||
|
||||
Define a member function `add()` that takes a generic `item` argument, creates
|
||||
a `DecoratedCrate` with it and adds the result to the `ArrayList`. The code in
|
||||
`main()` tests your solution.
|
||||
`main()` tests your solution.
|
||||
|
||||
<sub> This task doesn't contain the automatic tests,
|
||||
it's always marked as "Correct" on "Check".
|
||||
Please compare your solution with the provided one! </sub>
|
|
@ -3,4 +3,8 @@
|
|||
Convert `InCrate` and `OutCrate` to interfaces. Create a new version of `Crate`
|
||||
that implements both `InCrate` and `OutCrate`. The code in `main()` tests your
|
||||
solution by upcasting from `Crate<Grape>` to `OutCrate<Can>` and from
|
||||
`Crate<Can>` to `InCrate<Grape>`.
|
||||
`Crate<Can>` to `InCrate<Grape>`.
|
||||
|
||||
<sub> This task doesn't contain the automatic tests,
|
||||
it's always marked as "Correct" on "Check".
|
||||
Please compare your solution with the provided one! </sub>
|
|
@ -17,4 +17,8 @@ and return the `Map` in immutable form.
|
|||
|
||||
The code in `main()` tests your functions against the standard library
|
||||
versions. Notice that `buildList()` and `buildMap()` infer their generic
|
||||
parameters.
|
||||
parameters.
|
||||
|
||||
<sub> This task doesn't contain the automatic tests,
|
||||
it's always marked as "Correct" on "Check".
|
||||
Please compare your solution with the provided one! </sub>
|
|
@ -8,4 +8,8 @@ default untoasted.
|
|||
Add a function `sandwich3()` which is an extension function for `Sandwich`. The
|
||||
user can provide a `Sandwich` receiver that may or may not be already toasted.
|
||||
|
||||
The starter code and the code in `main()` tests your functions.
|
||||
The starter code and the code in `main()` tests your functions.
|
||||
|
||||
<sub> This task doesn't contain the automatic tests,
|
||||
it's always marked as "Correct" on "Check".
|
||||
Please compare your solution with the provided one! </sub>
|
|
@ -2,4 +2,8 @@
|
|||
|
||||
The starter code contains definitions for `class Cleanser` and `class
|
||||
SprayCleanser`. Write the functions `cleanser()` and `sprayCleanser()` so the
|
||||
code in `main()` works correctly.
|
||||
code in `main()` works correctly.
|
||||
|
||||
<sub> This task doesn't contain the automatic tests,
|
||||
it's always marked as "Correct" on "Check".
|
||||
Please compare your solution with the provided one! </sub>
|
|
@ -6,4 +6,8 @@ a `lateinit` property `powerPlant`.
|
|||
|
||||
Create a `lateinit` `car` at file scope, and a `lateinit` `truck` inside
|
||||
`main()`. Initialize `car` inside `main()`, giving it an electric motor,
|
||||
then initialize `truck`, giving it a combustion engine.
|
||||
then initialize `truck`, giving it a combustion engine.
|
||||
|
||||
<sub> This task doesn't contain the automatic tests,
|
||||
it's always marked as "Correct" on "Check".
|
||||
Please compare your solution with the provided one! </sub>
|
|
@ -8,4 +8,8 @@ to create and initialize an `A`. The code in `main()` tests your solution.
|
|||
|
||||
If `A` is the library someone else has created and that you are consuming,
|
||||
`lazy` initialization can be a convenient way to configure its `lateinit`
|
||||
properties.
|
||||
properties.
|
||||
|
||||
<sub> This task doesn't contain the automatic tests,
|
||||
it's always marked as "Correct" on "Check".
|
||||
Please compare your solution with the provided one! </sub>
|
|
@ -1,3 +1,7 @@
|
|||
## Lazy Initialization (#1)
|
||||
|
||||
Modify `PropertyOptions.kt` so that "Compute 4" appears in the trace.
|
||||
Modify `PropertyOptions.kt` so that "Compute 4" appears in the trace.
|
||||
|
||||
<sub> This task doesn't contain the automatic tests,
|
||||
it's always marked as "Correct" on "Check".
|
||||
Please compare your solution with the provided one! </sub>
|
|
@ -5,4 +5,8 @@ Create a class `Outer` containing an `inner class` called `Inner`, both with an
|
|||
`String` `val`s, each with an initializer tracing "Initializing <class
|
||||
name>.<property name>": `s1` and `s2` in `Outer`, and `si` in `Inner`. The
|
||||
initializers produce "Hi" for `s1`, "Hello $s1" for `s2`, and "Howdy $s2" for
|
||||
`si`. The starter code in `main()` tests your solution.
|
||||
`si`. The starter code in `main()` tests your solution.
|
||||
|
||||
<sub> This task doesn't contain the automatic tests,
|
||||
it's always marked as "Correct" on "Check".
|
||||
Please compare your solution with the provided one! </sub>
|
|
@ -17,4 +17,8 @@ In `B`, add `fun g()` that produces `j`. In `A`, add `fun f()` that produces
|
|||
|
||||
In `main()`, add a lazily-initialized `val a` that traces its initialization
|
||||
as above and then produces an `A` object. The remainder of `main()` is starter
|
||||
code that tests your solution.
|
||||
code that tests your solution.
|
||||
|
||||
<sub> This task doesn't contain the automatic tests,
|
||||
it's always marked as "Correct" on "Check".
|
||||
Please compare your solution with the provided one! </sub>
|
|
@ -13,4 +13,8 @@ Write member functions so that you can increment and decrement a `WrapRange`
|
|||
object but `current` automatically stays within `range`.
|
||||
|
||||
Make any necessary modifications so the starter code in `main()` produces the
|
||||
exercise output shown.
|
||||
exercise output shown.
|
||||
|
||||
<sub> This task doesn't contain the automatic tests,
|
||||
it's always marked as "Correct" on "Check".
|
||||
Please compare your solution with the provided one! </sub>
|
|
@ -14,4 +14,8 @@ enum class Count {
|
|||
Create extension functions to perform the operations `++` and `--` on a `Count`
|
||||
such that if `++` tries to go past `Moe`, it wraps around to `Eeny`, and if
|
||||
`--` tries to go below `Eeny`, it wraps around to `Moe`. The starter code
|
||||
in `main()` will check your work.
|
||||
in `main()` will check your work.
|
||||
|
||||
<sub> This task doesn't contain the automatic tests,
|
||||
it's always marked as "Correct" on "Check".
|
||||
Please compare your solution with the provided one! </sub>
|
|
@ -18,4 +18,8 @@ operations for a `Repository` named `r`:
|
|||
Add a `toString()` that produces `list` separated by commas.
|
||||
|
||||
The starter code in `main()` tests `Repository` and shows you how the error
|
||||
messages should appear.
|
||||
messages should appear.
|
||||
|
||||
<sub> This task doesn't contain the automatic tests,
|
||||
it's always marked as "Correct" on "Check".
|
||||
Please compare your solution with the provided one! </sub>
|
|
@ -9,4 +9,8 @@ for `notNull()`.
|
|||
Using `capture` from `atomictest`, try reading from `d`, `s` and `f` before
|
||||
they are initialized and validate the output using `atomictest.eq`. Then set
|
||||
`d` to `1.1`, `s` to `"yes"` and `f` to `Flag(true)` and use `eq` to verify
|
||||
that they all take on the new values.
|
||||
that they all take on the new values.
|
||||
|
||||
<sub> This task doesn't contain the automatic tests,
|
||||
it's always marked as "Correct" on "Check".
|
||||
Please compare your solution with the provided one! </sub>
|
|
@ -12,4 +12,8 @@ class Product(nm: String = "<0>", id: Int = -1) {
|
|||
}
|
||||
```
|
||||
|
||||
And that the starter code in `main()` successfully executes.
|
||||
And that the starter code in `main()` successfully executes.
|
||||
|
||||
<sub> This task doesn't contain the automatic tests,
|
||||
it's always marked as "Correct" on "Check".
|
||||
Please compare your solution with the provided one! </sub>
|
|
@ -2,4 +2,8 @@
|
|||
|
||||
Create a `class PositiveInt(i: Int)` containing a property `var n` such that
|
||||
any value assigned to `n` can only be greater than zero. The starter code in
|
||||
`main()` will test your solution.
|
||||
`main()` will test your solution.
|
||||
|
||||
<sub> This task doesn't contain the automatic tests,
|
||||
it's always marked as "Correct" on "Check".
|
||||
Please compare your solution with the provided one! </sub>
|
|
@ -1,4 +1,8 @@
|
|||
## Property Delegation (#1)
|
||||
|
||||
Convert `Configuration.kt` to use a `Map` instead of a file. The starter code
|
||||
in `main()` tests your new `Configuration` class.
|
||||
in `main()` tests your new `Configuration` class.
|
||||
|
||||
<sub> This task doesn't contain the automatic tests,
|
||||
it's always marked as "Correct" on "Check".
|
||||
Please compare your solution with the provided one! </sub>
|
|
@ -2,4 +2,8 @@
|
|||
|
||||
Starting with `Add.kt`, add a `setValue()` extension function to `Sum` that
|
||||
assigns its `value` argument to `a` in `Add` (change `Add` to make this work).
|
||||
The starter code in `main()` tests your solution.
|
||||
The starter code in `main()` tests your solution.
|
||||
|
||||
<sub> This task doesn't contain the automatic tests,
|
||||
it's always marked as "Correct" on "Check".
|
||||
Please compare your solution with the provided one! </sub>
|
|
@ -21,4 +21,8 @@ class Delegator {
|
|||
...
|
||||
```
|
||||
|
||||
And explain what happens.
|
||||
And explain what happens.
|
||||
|
||||
<sub> This task doesn't contain the automatic tests,
|
||||
it's always marked as "Correct" on "Check".
|
||||
Please compare your solution with the provided one! </sub>
|
|
@ -18,4 +18,8 @@ class Holders {
|
|||
}
|
||||
```
|
||||
|
||||
The starter code in `main()` will test your solution.
|
||||
The starter code in `main()` will test your solution.
|
||||
|
||||
<sub> This task doesn't contain the automatic tests,
|
||||
it's always marked as "Correct" on "Check".
|
||||
Please compare your solution with the provided one! </sub>
|
|
@ -9,4 +9,8 @@ initialize it with `NumPair(30, 40)` that has an `also` scope that adds 7 to
|
|||
Define `val result1` initialized with `np1.run` where the lambda sums the
|
||||
results of `add()`, `subtract()`, and `multiply()`. Use `eq` to check the
|
||||
result. Duplicate this functionality creating `result2` using `let` and
|
||||
`result3` using `with`.
|
||||
`result3` using `with`.
|
||||
|
||||
<sub> This task doesn't contain the automatic tests,
|
||||
it's always marked as "Correct" on "Check".
|
||||
Please compare your solution with the provided one! </sub>
|
|
@ -15,4 +15,8 @@ each. At the closing `}` of the scope function, chain the result to a `let`
|
|||
block, which increments `velocity`, then performs the same operations. At the
|
||||
end of that block, chain to a `run` block, then an `apply` block and an `also`
|
||||
block, performing the same operations in each block. Use `trace` to verify the
|
||||
output.
|
||||
output.
|
||||
|
||||
<sub> This task doesn't contain the automatic tests,
|
||||
it's always marked as "Correct" on "Check".
|
||||
Please compare your solution with the provided one! </sub>
|
|
@ -5,4 +5,8 @@ with a `run` scope. Inside that scope, define `val z` which is initialized by
|
|||
calling `np(11, 7)` with an `apply` scope. Inside that scope call `add() +
|
||||
subtract()` and after closing the scope, call `calc()`. Use `eq` to check that
|
||||
the result is 77. The return value from the `run()` scope is `z + add()`; use
|
||||
`eq` to check that the result is 1077.
|
||||
`eq` to check that the result is 1077.
|
||||
|
||||
<sub> This task doesn't contain the automatic tests,
|
||||
it's always marked as "Correct" on "Check".
|
||||
Please compare your solution with the provided one! </sub>
|
|
@ -11,4 +11,8 @@ and `secondHalf()` so it does the same for the second five, ignoring the first
|
|||
five. Define `interspersed()` so that it captures and displays the first
|
||||
element and every other one, ignoring the elements in between.
|
||||
|
||||
The starter code in `main()` tests your work.
|
||||
The starter code in `main()` tests your work.
|
||||
|
||||
<sub> This task doesn't contain the automatic tests,
|
||||
it's always marked as "Correct" on "Check".
|
||||
Please compare your solution with the provided one! </sub>
|
|
@ -18,4 +18,8 @@ and 8 removed. Display the list with the element 10 removed. Use the
|
|||
- `plus()`: Create a `var list` by adding 11, 12 and 13 to the result of
|
||||
`create()`. Use the "increment-equals" to append 14, and display the result.
|
||||
|
||||
The starter code in `main()` tests your work.
|
||||
The starter code in `main()` tests your work.
|
||||
|
||||
<sub> This task doesn't contain the automatic tests,
|
||||
it's always marked as "Correct" on "Check".
|
||||
Please compare your solution with the provided one! </sub>
|
|
@ -17,4 +17,8 @@ output.
|
|||
The calculation in `compareTo()` impacts numerous operations including those
|
||||
for using the object as a key in a `Map` and an element in a `Set`. As this
|
||||
exercise shows, you should be very reluctant to allow the values used in the
|
||||
`compareTo()` calculation to vary.
|
||||
`compareTo()` calculation to vary.
|
||||
|
||||
<sub> This task doesn't contain the automatic tests,
|
||||
it's always marked as "Correct" on "Check".
|
||||
Please compare your solution with the provided one! </sub>
|
|
@ -16,4 +16,8 @@ Create a function `fun g(d: Double): Double` that uses `require()` to ensure
|
|||
that `d` is greater than zero and less than or equal to 10.0. Do not provide a
|
||||
custom error message for `require()`. If the `require()` succeeds, return `d`.
|
||||
|
||||
The starter code in `main()` tests `f()` and `g()`.
|
||||
The starter code in `main()` tests `f()` and `g()`.
|
||||
|
||||
<sub> This task doesn't contain the automatic tests,
|
||||
it's always marked as "Correct" on "Check".
|
||||
Please compare your solution with the provided one! </sub>
|
|
@ -7,4 +7,8 @@ new functions as:
|
|||
|
||||
- `gn(d: Double?): Double`
|
||||
|
||||
The starter code in `main()` tests `fn()` and `gn()`.
|
||||
The starter code in `main()` tests `fn()` and `gn()`.
|
||||
|
||||
<sub> This task doesn't contain the automatic tests,
|
||||
it's always marked as "Correct" on "Check".
|
||||
Please compare your solution with the provided one! </sub>
|
|
@ -16,4 +16,8 @@ Add a function `up()` that increments `level` only if the result is within
|
|||
is within `range`. Finally, add a function `set(new: Int)` that first ensures
|
||||
that `new` is within `range` and then assigns `new` to `level`.
|
||||
|
||||
`Level` is tested by the starter code in `main()`.
|
||||
`Level` is tested by the starter code in `main()`.
|
||||
|
||||
<sub> This task doesn't contain the automatic tests,
|
||||
it's always marked as "Correct" on "Check".
|
||||
Please compare your solution with the provided one! </sub>
|
|
@ -49,4 +49,8 @@ case, catch the potential exception, and call `trace()` on that exception.
|
|||
expected output for `trace`.
|
||||
|
||||
Consider the complexity of the resulting code, and evaluate which exceptions
|
||||
could be replaced with ordinary non-exceptional code.
|
||||
could be replaced with ordinary non-exceptional code.
|
||||
|
||||
<sub> This task doesn't contain the automatic tests,
|
||||
it's always marked as "Correct" on "Check".
|
||||
Please compare your solution with the provided one! </sub>
|
|
@ -30,4 +30,8 @@ Notice the potential effects produced by exceptions:
|
|||
can be significantly more complicated.
|
||||
|
||||
2. The concept of recovery assumes that there's a *way* you can recover from a
|
||||
failed function call. Often, however, this is simply not true.
|
||||
failed function call. Often, however, this is simply not true.
|
||||
|
||||
<sub> This task doesn't contain the automatic tests,
|
||||
it's always marked as "Correct" on "Check".
|
||||
Please compare your solution with the provided one! </sub>
|
|
@ -36,4 +36,8 @@ exception rather than returning `Failed`. In contrast, a failure when closing a
|
|||
network connection isn't particularly problematic.
|
||||
|
||||
Again, notice how rapidly things get complicated when attempting to recover
|
||||
from all possible failures.
|
||||
from all possible failures.
|
||||
|
||||
<sub> This task doesn't contain the automatic tests,
|
||||
it's always marked as "Correct" on "Check".
|
||||
Please compare your solution with the provided one! </sub>
|
|
@ -17,4 +17,8 @@ Create a member function `checkLevel()` that uses a `when` expression. When
|
|||
- 10: call `error()`
|
||||
|
||||
The log message for each call is just "Level " followed by the matched value.
|
||||
The starter code in `main()` tests your solution.
|
||||
The starter code in `main()` tests your solution.
|
||||
|
||||
<sub> This task doesn't contain the automatic tests,
|
||||
it's always marked as "Correct" on "Check".
|
||||
Please compare your solution with the provided one! </sub>
|
|
@ -11,4 +11,8 @@ Handling](#exception-handling), use `AtomicLog.kt` to log exceptions into the
|
|||
|
||||
- Look for code where none of the exceptions are recoverable, and compact it if
|
||||
you can to log to `error()` and fail, rather than having multiple `catch`
|
||||
clauses.
|
||||
clauses.
|
||||
|
||||
<sub> This task doesn't contain the automatic tests,
|
||||
it's always marked as "Correct" on "Check".
|
||||
Please compare your solution with the provided one! </sub>
|
|
@ -5,4 +5,8 @@ Add logging levels to `AtomicLog.kt`. Create an enumeration `Level` with values
|
|||
called `debugLevel` at file scope, initialized to `Error`. Inside your new
|
||||
`Logger` class, modify the `log()` function so its signature is `private fun
|
||||
log(thisLevel: Level, msg: String)`. This will require small modifications to
|
||||
some other functions. The code in `main()` tests your solution.
|
||||
some other functions. The code in `main()` tests your solution.
|
||||
|
||||
<sub> This task doesn't contain the automatic tests,
|
||||
it's always marked as "Correct" on "Check".
|
||||
Please compare your solution with the provided one! </sub>
|
|
@ -6,4 +6,8 @@ function that uses `java.io.File`. Create a `File` object initialized to
|
|||
the file (IntelliJ IDEA will give you hints to help choose the member functions
|
||||
to call for `File`). Use `useLines()` to read the file and display it with
|
||||
`println()`, then use `forEachLine()` to read the file and display it with
|
||||
`println()`. The starter code in `main()` tests `writeAndRead()`.
|
||||
`println()`. The starter code in `main()` tests `writeAndRead()`.
|
||||
|
||||
<sub> This task doesn't contain the automatic tests,
|
||||
it's always marked as "Correct" on "Check".
|
||||
Please compare your solution with the provided one! </sub>
|
|
@ -3,4 +3,8 @@
|
|||
Create your own `AutoCloseable` class called `Cleanup`, containing `f()`, `g()`,
|
||||
`h()` and `close()` that use `println()` to display `"f()"`, `"g()"`, `"h()"`
|
||||
and `"close()"`, respectively. In `main()`, create a `Cleanup` object and call
|
||||
`f()`, `g()` and `h()` via `use()`.
|
||||
`f()`, `g()` and `h()` via `use()`.
|
||||
|
||||
<sub> This task doesn't contain the automatic tests,
|
||||
it's always marked as "Correct" on "Check".
|
||||
Please compare your solution with the provided one! </sub>
|
|
@ -18,4 +18,8 @@ Define a function `verifyClose(opt: Option)`. `verifyClose()` creates a
|
|||
- `Throw`: `f()` is called and then an `Exception` is thrown from
|
||||
the middle of the `use()` block.
|
||||
|
||||
`main()` tests your code.
|
||||
`main()` tests your code.
|
||||
|
||||
<sub> This task doesn't contain the automatic tests,
|
||||
it's always marked as "Correct" on "Check".
|
||||
Please compare your solution with the provided one! </sub>
|
|
@ -6,4 +6,8 @@ String)` that passes `msg` to `trace()`, and then throws a `Failure`.
|
|||
|
||||
Now write your own versions of `require()` and `check()` (from [Check
|
||||
Instructions](#check-instructions)) that use `fail()`. The starter code in
|
||||
`main()` tests your functions.
|
||||
`main()` tests your functions.
|
||||
|
||||
<sub> This task doesn't contain the automatic tests,
|
||||
it's always marked as "Correct" on "Check".
|
||||
Please compare your solution with the provided one! </sub>
|
|
@ -8,4 +8,8 @@ Modify Exercise 1 by creating an `object Log` that contains a `private` mutable
|
|||
- `report()`: Produces a non-modifiable copy of `messages`
|
||||
|
||||
In `fail()`, add the `msg` to `Log` before throwing `Failure`. The starter
|
||||
code in `main()` tests your work.
|
||||
code in `main()` tests your work.
|
||||
|
||||
<sub> This task doesn't contain the automatic tests,
|
||||
it's always marked as "Correct" on "Check".
|
||||
Please compare your solution with the provided one! </sub>
|
|
@ -5,4 +5,8 @@ Create `Failure` and `fail()` as in the previous two exercises, but do not call
|
|||
it to `true`. Define `fun debug(test: Boolean)` so that it always calls
|
||||
`trace()` to verify that it was called (see the starter code in `main()` to
|
||||
discover the format of the `trace()` message), but only performs the `debug()`
|
||||
activity if `_debug` is `true`. The starter code in `main()` tests your work.
|
||||
activity if `_debug` is `true`. The starter code in `main()` tests your work.
|
||||
|
||||
<sub> This task doesn't contain the automatic tests,
|
||||
it's always marked as "Correct" on "Check".
|
||||
Please compare your solution with the provided one! </sub>
|
|
@ -3,4 +3,8 @@
|
|||
Starting with `SealedClasses/SealedClasses.kt`, test the function `travel()`
|
||||
using the code in `main()` as inspiration. Create two test functions named
|
||||
"train travel" and "bus travel" and use `assertEquals()` from `kotlin.test` to
|
||||
compare the expected output to the actual output.
|
||||
compare the expected output to the actual output.
|
||||
|
||||
<sub> This task doesn't contain the automatic tests,
|
||||
it's always marked as "Correct" on "Check".
|
||||
Please compare your solution with the provided one! </sub>
|
|
@ -3,4 +3,8 @@
|
|||
Test the classes in `Interfaces/Computer.kt`. Create one test class for each
|
||||
type of `Computer`, and use the default test function names created by IntelliJ
|
||||
IDEA. Use `assertEquals()` from `kotlin.test` to compare the expected output to
|
||||
the actual output.
|
||||
the actual output.
|
||||
|
||||
<sub> This task doesn't contain the automatic tests,
|
||||
it's always marked as "Correct" on "Check".
|
||||
Please compare your solution with the provided one! </sub>
|
|
@ -12,4 +12,8 @@ infix fun <T> T.aeq(actual: T) =
|
|||
assertEquals(this, actual)
|
||||
```
|
||||
|
||||
To use `aeq`: *expectedValue* `aeq` *actualValue*.
|
||||
To use `aeq`: *expectedValue* `aeq` *actualValue*.
|
||||
|
||||
<sub> This task doesn't contain the automatic tests,
|
||||
it's always marked as "Correct" on "Check".
|
||||
Please compare your solution with the provided one! </sub>
|
Loading…
Reference in New Issue