From ce717da44a2b2190471731a8c3f80413134a07fd Mon Sep 17 00:00:00 2001 From: Martin Goik <goik@hdm-stuttgart.de> Date: Tue, 1 Apr 2014 07:49:56 +0200 Subject: [PATCH] Exercise preperation enum --- Sd1/swd1.xml | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 94 insertions(+), 2 deletions(-) diff --git a/Sd1/swd1.xml b/Sd1/swd1.xml index 3aad882f9..7340a2428 100644 --- a/Sd1/swd1.xml +++ b/Sd1/swd1.xml @@ -454,8 +454,53 @@ allows for setting the direction a wombat is going to move. Call it inserting different values by right clicking on a wombat instance. How do entered values relate to directions of a - wombat's movement? You may evaluate the result by actually - watching its moving direction. Is there another way?</para> + wombat's movement? Complete the following table by adding North, + South, East and West accordingly:</para> + + <informaltable border="1" width="40%"> + <colgroup width="45%"/> + + <colgroup width="55%"/> + + <tr> + <th>Integer value</th> + + <th>Direction</th> + </tr> + + <tr> + <td>0</td> + + <td/> + </tr> + + <tr> + <td>1</td> + + <td/> + </tr> + + <tr> + <td>2</td> + + <td/> + </tr> + + <tr> + <td>3</td> + + <td/> + </tr> + + <tr> + <td>other</td> + + <td/> + </tr> + </informaltable> + + <para>You may evaluate the result by actually watching its + moving direction. Is there another way?</para> <para>Hint: The <productname>Greenfoot</productname> framework allows you to inspect an object's internal attribute @@ -519,6 +564,53 @@ </answer> </qandaentry> </qandadiv> + + <qandadiv> + <qandaentry> + <question> + <para>Representing directions by integer values ranging from 1 + to 4 may be considered error prone. Explain possible + problems.</para> + + <para>Hint: The <productname>Greenfoot</productname> + <filename>leaves-and-wombats</filename> scenario code contains + statements like <code>setDirection(EAST)</code>. But what about + <code>setDirection(35)</code> ?</para> + </question> + + <answer> + <glosslist> + <para>A programmer may consistently use the predefined integer + values <code>EAST</code>, <code>WEST</code>, + <code>NORTH</code> and <code>SOUTH</code> but may use ordinary + integer values {0, 1, 2, 3} as well. This imposes the + following problems:</para> + + <glossentry> + <glossterm>Code Readability</glossterm> + + <glossdef> + <para>A statement like <code>setDirection(2)</code> will + be more difficult to understand than its counterpart + <code>setDirection(NORTH)</code>. Currently we cannot + enforce the second way of coding.</para> + </glossdef> + </glossentry> + + <glossentry> + <glossterm>Possible programming errors</glossterm> + + <glossdef> + <para>A programmer may be misled to use illegal + directional values. Keeping a wrong set of directions in + mind e.g {1, 2, 3, 4} rather than {0, 1, 2, 3} will result + in errors. These may be hard to trace </para> + </glossdef> + </glossentry> + </glosslist> + </answer> + </qandaentry> + </qandadiv> </qandaset> </section> -- GitLab