diff --git a/hugo/content/classes/ws2023/info1/labs/exercise-02.md b/hugo/content/classes/ws2023/info1/labs/exercise-02.md index d2786344d..4f27c570d 100644 --- a/hugo/content/classes/ws2023/info1/labs/exercise-02.md +++ b/hugo/content/classes/ws2023/info1/labs/exercise-02.md @@ -77,7 +77,7 @@ Use the project `chapter02/kara/kara-clock-lab02` for these exercises. #### 1. Multi-Move 0. Open the project `chapter02/kara/kara-clock-lab02`. It contains several test worlds. Make sure you've instantiated the correct test world! -1. copy the multiMove method we discussed in class from `chapter02/kara/kara-loop-examples` to DigitDisplayKara. Test it in TestWorld0 and TestWorld1. TestWorld1 contains a setup you don't need to understand just now - just click "act" once and all Karas should be aligned in the middle like this: +1. copy the multiMove method we discussed in class from `chapter02/kara/kara-loop-examples` to DigitDisplayKara (the method definition is already there, you just need to fill it). Test it in TestWorld0 and TestWorld1. TestWorld1 contains a setup you don't need to understand just now - just click "act" once and all Karas should be aligned in the middle like this: | Initial TestWorld1 | TestWorld1 after act() | |:----------------------------------------------|:--------------------------------------------| @@ -93,6 +93,18 @@ you're done test it in TestWorld2: #### 2. Count Leaves +1. Open TestWorld4. complete the method `public int moveUpAndCount()` in `DigitDisplayKara`. + It should move up and count the leaves. It should stop either at the tree above or on the first free field. It returns the number of leaves counted. + Test your method by calling it from Kara's context menu. +2. When you're done, test your method in TestWorld5, which contains some edge cases like a full row and one with zero leaves. + +| TestWorld5 before| TestWorld5 output | TestWorld5 after act() | +|:--|:----------------------------------------------|:--------------------------------------------| +| ![TestWorld5 before](./testworld5-before.jpg) | ![TestWorld5 output](./testworld5-output.jpg) | ![TestWorld5 after](./testworld5-after.jpg) | + +#### 3. Preview +The next step would be a `public int countLeaves()` method that combines `public int moveUpAndCount()` and the `public void multiMove(int n)` methods: it counts the leaves and returns back to the home position. But we will do this next week! + ## What to hand in Hand in your lab report (pdf) and your code (zip) the night before the next lab, 10pm (22.00 Uhr). See [the Labs and Exercises page](../). diff --git a/hugo/content/classes/ws2023/info1/labs/exercise-02/testworld5-after.jpg b/hugo/content/classes/ws2023/info1/labs/exercise-02/testworld5-after.jpg new file mode 100644 index 000000000..906e86bb6 Binary files /dev/null and b/hugo/content/classes/ws2023/info1/labs/exercise-02/testworld5-after.jpg differ diff --git a/hugo/content/classes/ws2023/info1/labs/exercise-02/testworld5-before.jpg b/hugo/content/classes/ws2023/info1/labs/exercise-02/testworld5-before.jpg new file mode 100644 index 000000000..b879452fa Binary files /dev/null and b/hugo/content/classes/ws2023/info1/labs/exercise-02/testworld5-before.jpg differ diff --git a/hugo/content/classes/ws2023/info1/labs/exercise-02/testworld5-output.jpg b/hugo/content/classes/ws2023/info1/labs/exercise-02/testworld5-output.jpg new file mode 100644 index 000000000..1102acaef Binary files /dev/null and b/hugo/content/classes/ws2023/info1/labs/exercise-02/testworld5-output.jpg differ