Commit 7f9611b7 authored by Dr. Martin Goik's avatar Dr. Martin Goik

Missing exam file

parent 634e2dd1
<?xml version="1.0" encoding="UTF-8"?>
<section version="5.0" xml:id="exam_summer2020" xml:lang="en"
xmlns="http://docbook.org/ns/docbook"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:xila="http://www.w3.org/2001/XInclude/local-attributes"
xmlns:xi="http://www.w3.org/2001/XInclude"
xmlns:trans="http://docbook.org/ns/transclusion"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns:m="http://www.w3.org/1998/Math/MathML"
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns:db="http://docbook.org/ns/docbook">
<title>SD1 examination summer 2020</title>
<section xml:id="sd1_exam_2020_summer_task1">
<title>Implementing tasks</title>
<section xml:id="sd1_exam_2020_summer_task1_preparation">
<title>Preparation</title>
<para>Download and unzip the above file <filename>exam.zip</filename>.
Then import the resulting <filename>Exam</filename> Project into your
<productname>IDEA</productname> IDE by choosing »File --&gt; Open...«
subsequently selecting the <filename>Exam/pom.xml</filename>
file.</para>
</section>
<section xml:id="sd1_exam_2020_summer_task1_description">
<title>Description</title>
<para>Your imported project contains:</para>
<itemizedlist>
<listitem>
<para>Partial implementations of classes and methods.</para>
</listitem>
<listitem>
<para><productname>Javadoc</productname> comments describing the
desired behaviour</para>
</listitem>
<listitem>
<para><productname>Junit</productname> tests for testing the desired
(not yet implemented) behaviour.</para>
</listitem>
</itemizedlist>
</section>
<section xml:id="sd1_exam_2020_summer_task1_tasks">
<title>Tasks</title>
<para>Complete the implementation of classes and methods in both
packages <package>de.hdm_stuttgart.mi.sd1.task1</package> and
<package>de.hdm_stuttgart.mi.sd1.task2</package>. Your project's
<filename>test</filename> branch contains corresponding
<productname>Junit</productname> tests for each class / method to be
implemented.</para>
</section>
<section xml:id="sd1_exam_2020_summer_task1_hints">
<title>Hints</title>
<itemizedlist>
<listitem>
<para>Your score solely depends on the number of successfully
executing unit tests. A »nearly correct« implementation failing with
respect to a given unit tests will contribute no points at
all.</para>
<para>General advice: Implement less but correctly.</para>
</listitem>
<listitem>
<para>Mind special cases <abbrev>i.e.</abbrev> <code>null</code>
variable values or <code>null</code> values being contained in
arrays.</para>
</listitem>
<listitem>
<para>In case of test failures both the
<productname>IDEA</productname> debugger and logging statements are
your friend.</para>
</listitem>
<listitem>
<para>Executing
<package>de.hdm_stuttgart.mi.sd1.test</package>.<classname>ShowReachedPoints</classname>
in your project's <filename>test</filename> branch as a
<productname>Java</productname> application (not as
<productname>Junit</productname> test!) shows your number of points
reached so far.</para>
</listitem>
</itemizedlist>
</section>
<section version="5.1" xml:id="sd1_exam_2020_summer_uploadFirst">
<title>Project upload</title>
<para>Export your project by hitting »File« --&gt; »Export to Zip File«
in IDEA creating an <abbrev>e.g.</abbrev>
<filename>solution-1.zip</filename> file. Hit the <quote> choose
file</quote> button in your <productname>ILIAS</productname> browser tab
and select <filename>solution-1.zip</filename>. Subsequently click
<quote>upload</quote>. Do not forget to advance to the next question for
actually saving your upload. Common pitfalls:</para>
<itemizedlist>
<listitem>
<para>Do not select the wrong archive! In particular avoid choosing
the original <filename>exam.zip</filename> skeleton.</para>
</listitem>
<listitem>
<para>After uploading check for <filename>solution_1.zip</filename>
being visible in the examination system.</para>
</listitem>
<listitem>
<para>You may upload multiple versions i.e.
<filename>solution_2.zip</filename> etc. . Only your least uploaded
archive will become subject to marking.</para>
</listitem>
</itemizedlist>
</section>
<section xml:id="sd1_exam_2020_summer_examCaveats">
<title>Caveats</title>
<itemizedlist>
<listitem>
<para>When approaching examination ending time check your input for
completeness.</para>
</listitem>
<listitem>
<para>Projects residing just on your local workstation cannot be
recovered after exam termination.</para>
</listitem>
</itemizedlist>
</section>
</section>
<section xml:id="sd1_exam_2020_summer_task2">
<title>Return type</title>
<qandaset defaultlabel="qanda" xml:id="sd1_exam_2020_summer_task2Qanda">
<qandadiv>
<qandaentry>
<question>
<para>We consider a method computing a circle's area:</para>
<programlisting language="java">static public float getArea (int radius) {
return radius * radius * 3.1415926;
}</programlisting>
<orderedlist>
<listitem>
<para>Compilation fails due to the following error:</para>
<screen>Required type: float
Provided: double</screen>
<para>Explain the error message.</para>
<tip>
<para>Dissect the underlying expression.</para>
</tip>
</listitem>
<listitem>
<para>You are not allowed to change the method's signature.
What is the cleanest way to correct the programming
error?</para>
</listitem>
</orderedlist>
</question>
<answer>
<orderedlist>
<listitem>
<para>The expression <code>radius * radius * 3.1415926</code>
is being evaluated from left to right. The literal
<code>3.1415926</code> is of type double. We thus have:</para>
<screen>int * int * double
⭨ ⭩ ⭩
int * double
⭨ ⭩
double</screen>
</listitem>
<listitem>
<para>The cleanest way is replacing the <code>double</code>
literal by a a <code>float</code> literal:</para>
<screen>radius * radius * 3.1415926<emphasis role="red">F</emphasis>
int * int * float
⭨ ⭩ ⭩
int * float
⭨ ⭩
float</screen>
<para>This resolves the return type clash.</para>
</listitem>
</orderedlist>
</answer>
</qandaentry>
</qandadiv>
</qandaset>
</section>
<section xml:id="sd1_exam_2020_summer_task3">
<title>Weird behaviour</title>
<qandaset defaultlabel="qanda" xml:id="sd1_exam_2020_summer_task3Qanda">
<qandadiv>
<qandaentry>
<question>
<para>We consider a method computing a given <code
language="java">int</code>'s square value:</para>
<programlisting language="java">static public int getSquare (int value) {
return value * value;
}</programlisting>
<para>A larger piece of software using this method produces
erroneous results. Tracing for possible errors the developing team
adds a logging statement:</para>
<programlisting language="java">static public int getSquare (int value) {
int result = value * value;
log.info(result);
return result;
}</programlisting>
<para>The team is baffled: Albeit squares of integer values are
expected to be always positive occasionally negative results show
up:</para>
<screen>INFO [main] sd1.SupportMethods (SupportMethods.java:15) - -1757895751</screen>
<orderedlist>
<listitem>
<para>Explain the underlying reason.</para>
</listitem>
<listitem>
<para>You are allowed to modify the method's signature.
Provide a solution.</para>
</listitem>
</orderedlist>
</question>
<answer>
<orderedlist>
<listitem>
<para>The problem is caused by arithmetic overflow errors. The
largest possible <code>int</code> is <inlineequation>
<m:math display="inline">
<m:mrow>
<m:msup>
<m:mi>2</m:mi>
<m:mi>31</m:mi>
</m:msup>
<m:mo>-</m:mo>
<m:mi>1</m:mi>
</m:mrow>
</m:math>
</inlineequation> or 2147483647. Its square root is
46340.95... .Thus up to the value of 46340 all squares are
being calculated correctly e.g.:</para>
<informaltable border="1">
<tr>
<th>Code</th>
<th>Result</th>
</tr>
<tr>
<td valign="top"><programlisting language="java">System.out.println(46340 * 46340);</programlisting></td>
<td valign="top"><screen>2147395600</screen></td>
</tr>
</informaltable>
<para>The product <code>46341 * 46341</code> of type
<code>int</code> however exceeds this value for the very first
time. Due to an <code>int</code>'s four-byte two complement
representation we have:</para>
<informaltable border="1">
<tr>
<th>Code</th>
<th>Result</th>
</tr>
<tr>
<td valign="top"><programlisting language="java">System.out.println(46341 * 46341);</programlisting></td>
<td valign="top"><screen>-2147479015</screen></td>
</tr>
</informaltable>
</listitem>
<listitem>
<para>Solving the issue requires a data type being able to
accommodate squares of arbitrary <code>int</code> values. The
smallest int value is <inlineequation>
<m:math display="inline">
<m:mrow>
<m:mo>-</m:mo>
<m:msup>
<m:mi>2</m:mi>
<m:mi>31</m:mi>
</m:msup>
</m:mrow>
</m:math>
</inlineequation> and its square thus <inlineequation>
<m:math display="inline">
<m:msup>
<m:mi>2</m:mi>
<m:mi>62</m:mi>
</m:msup>
</m:math>
</inlineequation>.We choose <code>long</code> as result
type. Turning an <code>int</code> into a long is easy:</para>
</listitem>
<listitem>
<para/>
</listitem>
</orderedlist>
</answer>
</qandaentry>
</qandadiv>
</qandaset>
</section>
</section>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment