Skip to content
Snippets Groups Projects
Commit e1cc454a authored by Goik Martin's avatar Goik Martin
Browse files

Completing exercise documentation

parent 27a9b83c
No related branches found
No related tags found
No related merge requests found
......@@ -136,18 +136,60 @@ public void testApp() {
}</programlisting>
<para>This interface may be used by the plotter class as a
<quote>placeholder</quote> for the intended plot function to be
defined as e.g.:</para>
<quote>placeholder</quote> for the intended plot function.
Plotting e.g. <function>y=sin(x)</function> will then be effected
by:</para>
<programlisting language="none">class MySin implements DoubleOfDoubleFunction {
@Override
public double compute(double x) {
return Math.sin(x);
}
}</programlisting>
<para>Plotting will then require an instance:</para>
<programlisting language="none">final DoubleOfDoubleFunction sinFunction = new MySin();
plotter.plot(sinFunction);</programlisting>
</question>
<answer>
<para/>
<annotation role="make">
<para role="eclipse">Sd1/plot/Basic</para>
<para>A <quote>standard</quote> plotting example is being
provided in class <classname>DriverInterface</classname>.</para>
</annotation>
<para>The above solution contains a variant using Java 8 Lambda
expressions which allows for supplying functions as arguments to
the plotting facility. This solution will not be covered in the
current lecture but you may catch a glimpse of upcoming topics in
<quote xml:lang="de">Softwareentwicklung 2</quote>.</para>
<para>The solution in addition contains a variant
<classname>DriverLambda</classname> using <link
xlink:href="http://tutorials.jenkov.com/java/lambda-expressions.html">Java
8 lambda expressions</link> which allows for supplying functions
as arguments to the plotting facility. This solution will not be
covered in the current lecture but you may catch a glimpse with
respect to upcoming topics in <quote
xml:lang="de">Softwareentwicklung 2</quote>:</para>
<programlisting language="none">public class DriverLambda {
/**
* @param args Unused
*/
public static void main( String[] args ) {
final Plotter plotter = new Plotter();
plotter.setNumTics(80, 40);// 80 characters vertical, 40 characters horizontal
plotter.setXrange(0, 2 * Math.PI);
plotter.setYrange(-1, 1);
// Function implementing the underlying interface
// de.hdm_stuttgart.mi.sd1.plot.DoubleOfDoubleFunction
// are being conveniently passed as arguments.
plotter.plot(<emphasis role="bold">x -&gt; Math.sin(x)</emphasis>);
plotter.plot(<emphasis role="bold">x -&gt; Math.cos(x)</emphasis>);
}
}</programlisting>
</answer>
</qandaentry>
</qandadiv>
......
......@@ -25,8 +25,7 @@ public class DriverInterface {
plotter.setXrange(0, 2 * Math.PI);
plotter.setYrange(-1, 1);
DoubleOfDoubleFunction sinFunction = new MySin();
final DoubleOfDoubleFunction sinFunction = new MySin();
plotter.plot(sinFunction);
}
}
......@@ -17,7 +17,8 @@ public class DriverLambda {
plotter.setXrange(0, 2 * Math.PI);
plotter.setYrange(-1, 1);
// Function implementing the underlying interface
// Function implementing the underlying interface
// de.hdm_stuttgart.mi.sd1.plot.DoubleOfDoubleFunction
// are being conveniently passed as arguments.
plotter.plot(x -> Math.sin(x));
plotter.plot(x -> Math.cos(x));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment